<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Util\SqlServerUtil;
use App\Util\GetMac;
use App\Util\Common;
use App\Services\OSS;
use App;
use Illuminate\Support\Facades\DB; 
use Illuminate\Database\Query\Builder;
use Illuminate\Database\QueryException;
use function Symfony\Component\Debug\header;
use Hamcrest\Type\IsNumeric;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use Illuminate\Support\Facades\Log;

class BaseController extends CommonController
{
	protected $DB = 'GenDB';
	
    protected $response = [
    		"Error" => 0,
    		"Message" => "Success!",
    		"Data" => []
	];
    
	/**
	* 聚一科技 ^_^
	* @date: 2020年12月4日
	* @author: lq
	* @version:App V2.0
	*/
	public function getfuzhuziliao(Request $request){
		$key = $request->key;
		$data = SqlServerUtil::execTosql($this->SqlServer,"select * from gz_SubMessage where FTypeID = '{$key}' order by fid" );
		if($data){
			
			$data = arraykeyToLowerTo($data);
			foreach ($data as $k =>&$v)
			{
				if($v['fdeleted'] ==1){
					
					$data[$k]['fdeletedstr'] =true; 
					
				}else{
					$data[$k]['fdeletedstr'] = false; 
					
				}
			}
		 }
		showMsg(0,'成功',$data);
	}
	
	/**
	*  修改辅助资料
	* @date: 2021年6月29日 下午2:25:44
	* @author: juyi
	*/
	public function editfuzhuziliao(Request $request){
		$isaddedit = $request ->isaddedit;
		//$db = $request ->db;
		$row = $request ->row;
		$opername = $request ->opername?$request ->opername:'';
		//1==新增，2--修改
		$ups =false;
		if($isaddedit == 2){
			$fdeleted =  $row['fdeletedstr']==true ?1:0;
			$finterid =['finterid'=>$row['finterid']] ; 
			$data=[
				'fid'=> $row['fid'],
				'fname'=> $row['fname'],
				'fdeleted'=>$fdeleted,
			];
			
			$ups = SqlServerUtil::exeupdateTosql($this->SqlServer,'gz_SubMessage',$data,$finterid);
			$this->writeLog('辅助资料','修改' , 13003 ,$row ,$opername );
		}else{
			$fdeleted =  $row['fdeletedstr']==true ?1:0;
			$finterid =['finterid'=>$row['finterid']] ;
			$data=[
					'fid'=> $row['fid'],
					'fname'=> $row['fname'],
					'fdeleted'=>$fdeleted,
					'ftypeid'=>$row['ftypeid'],
					'fbrno'=>'',
					'fparentid'=>0,
					
			];
			$ups = SqlServerUtil::sqlsrvCreate($this->SqlServer,'gz_SubMessage',$data);
			$this->writeLog('辅助资料','新增' , 13003 , $row ,$opername);
		}
		if($ups){
			showMsg(0,'成功');
		 }
		 showMsg(1,'失败');
	}
		
	public function delfuzhuziliao(Request $request){
		$row = $request ->row;
		$opername = $request ->opername?$request ->opername:'';
		$ups = SqlServerUtil::sqlsrvDelete($this->SqlServer,'gz_SubMessage',['finterid'=>$row['finterid']]);
		if($ups){
			$this->writeLog('辅助资料','删除' , 13003 ,$row ,$opername);
			showMsg(0,'成功');
		}
		showMsg(1,'失败');
	}
	
	//首页数据
	public function homeData(Request $request){
		$fyear =getCurrentTime(5);
		$syFPeriod =getCurrentTime(8);
		$FPeriod =getCurrentTime(8); 
		$sql ="select count(1) poorder from gz_admin  where  username !='manager'
    	UNION all
    	select count(1) poorder from gz_SubMessage   where FTypeID = 30 
		UNION all
		select count(1) poorder from gz_YbaojiadanCB  where  1 =1 
    	UNION all
    	select count(1) poorder from gz_Ypeijian where  1 =1 ";
		
		$result = SqlServerUtil::execTosqlOK($this->SqlServer, $sql);
		$temp= ['zy','sykq','by','sy'];
		$data =[];
		if($result && count($result)>0 ){
			foreach ($result as $k =>$v)
			{
				$data[$temp[$k]] = floatVal($v['poorder']);
			}
			
		}
		showMsg(0,'成功',$data);
	}
	
	
// 	参数值获取
	public function getCSData(Request $request){
		$FCategory = $request->fcategory;
		$FKeyStr ="";
		
		if(!empty($request->fkey)){
			$FKey = $request->fkey;
			$FKeyStr =  " and  FKey='{$FKey}' ";
		}
		
		$sql ="SELECT FKey, FValue from gz_SystemProfile where FCategory='{$FCategory}' {$FKeyStr}   ";
		$res=SqlServerUtil::exec1($this->SqlServer, strtolower($sql) );
		$result = [];
		if($res){
			foreach ($res as $k =>$v)
			{
				$result[strtolower($v['fkey'])] =  $v['fvalue'] ;
			}
			
		}
		showMsg(0,'成功',$result);
	}
	
	
	/**
	* 权限组 
	* 登录名  -- 是否属于最高权限组 
	* 系统管理员组 
	* 系统界面已锁定，仅管理员组可以操作
	* @date: 2022年10月25日 下午2:14:57
	* @author: juyi
	*/
	public function FLookset(Request $request){
		$loginname = $request->loginname;//登录名称
		
		//查询用户--权限组列表
		$group3 = "select a.username,a.id,ug.groupid,g.fname fgroupname  from gz_user_group ug 
		left join gz_admin a  on a.id= ug.userid left join gz_group g on g.id= ug.groupid  
		where 1=1 and a.status =1  and a.username = '{$loginname}' and ug.groupid=1   ";
		$usergroupList = SqlServerUtil::execToSql($this->SqlServer, $group3,2);
		
		if($usergroupList){
			
			showMsg(0,'成功' , true);
		}
		
		
		showMsg(1,'系统界面已锁定，仅系统管理员组可以操作',false);
	}
	
	
	//
	/**
	* 文件用途描述
	* @date: 2023年2月13日 下午2:10:59
	* @author: juyi
	*/
	public function FJZset(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername = $request->get('opername'); //当前登录人名称      '测试3'
		$fbrand = $request->get('fbrand'); //品牌 
		$bumen = $request->get('fdanweibumen');  
		
// 		$db = columnBiao($FRepKey);//表名  -- 
		
		$fkeywordStr  = "" ;
		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
			$keyword = $request->keyword  ;
			$fkeywordStr=" and ( charindex('{$keyword}',v1.fname)>0 or charindex('{$keyword}',v1.fcode)>0   )" ;
		}
		
		$bumenStr = "";
		if($request->fdanweibumen  == 1){
			
			//采购部
			$bumenName ="采购";
			$bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0   )" ;
			
		}elseif($request->fdanweibumen  == 2){
			//技术中心
			$bumenName ="技术";
			$bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0   )" ;
		}elseif($request->fdanweibumen  == 3){
			//其他部门    =  售后服务部、生产管理部  ， 质量管理部
			$bumenName ="售后";
			$bumenName1 ="生产";
			$bumenName2 ="质量";
			$bumenName3 ="其他";
			$bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0  or charindex('{$bumenName1}',v1.fdanweibumen)>0 or charindex('{$bumenName2}',v1.fdanweibumen)>0 or charindex('{$bumenName3}',v1.fdanweibumen)>0 )" ;
		}
		//品牌
		$fbrandStr = "";
		if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
			$fbrandStr = " and v1.fbrand = '{$fbrand}' " ; 
		}
		
		if($FRepKey == '14009'){
			//14009 -- 业务需求
			$baseSql =" select v1.*  from gz_YjiazhangcbfSet v1  where 1=1 {$fkeywordStr}  {$fbrandStr}" ;
		}elseif($FRepKey == '14011'){
			//14011 -- 业务需求(技术部)
			$baseSql =" select  v1.*  from gz_YjiazhangcbfSet v1  where 1=1  and ( charindex('技术',v1.fdanweibumen)>0   ) {$fkeywordStr}   {$fbrandStr}" ;
		}elseif($FRepKey == '14012'){
			//14012 -- 业务需求(采购部)
			$baseSql =" select  v1.*  from gz_YjiazhangcbfSet v1  where 1=1 and ( charindex('采购',v1.fdanweibumen)>0   ) {$fkeywordStr}  {$fbrandStr}" ;
		}elseif($FRepKey == '14013'){
			//14013 -- 业务需求(财务部)
			$baseSql =" select  v1.*  from gz_YjiazhangcbfSet v1  where 1=1 {$fkeywordStr}   {$fbrandStr}" ;
		}elseif($FRepKey == '26023' || $FRepKey == '26005' || $FRepKey == '26025'){
			// 加账设置
			// 	加账技部 26023
			if($FRepKey == '26023' ){
				if($request->fjs ==0 ){
					//全部
					$baseSql =" select v1.*  from gz_YjiazhangcbfSet v1  where 1=1 {$fkeywordStr}  {$fbrandStr}" ;
					
				}elseif($request->fjs == 1){
					//技术中心
					$baseSql =" select v1.*  from gz_YjiazhangcbfSet v1  where 1=1 {$fkeywordStr}  {$bumenStr}  {$fbrandStr}" ;
				}
			}else{
				$baseSql =" select v1.*  from gz_YjiazhangcbfSet v1  where 1=1 {$fkeywordStr}  {$bumenStr}  {$fbrandStr}" ;
			}
		}else{
			//采购账单
			$baseSql =" select v1.*  from gz_YcaigoucbfSet v1  where 1=1 {$fkeywordStr} {$bumenStr} {$fbrandStr}" ;
		}
// 		echo $baseSql;die;
		$res = SqlServerUtil::execTosqlOK($this->SqlServer,  $baseSql);
		$result =[];
		if($res){
			$result = arraykeyToLower($res);
			foreach ($result as $k1=>&$v1)
			{
				foreach ($v1 as $k2=>$v2)
				{
					if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000'  || ($v1[$k2]>0 && $v1[$k2]<1) ){
						$v1[$k2] = floatval($v2);
					}
					// fnbfhyx
				}
			}
			
			// 	加账技部 26023  == 这里 加账技术 部门 ，技术公式 做处理了 
			if( in_array($FRepKey, [ '26005', '26023','26025',   ]) ) {
				foreach ($result as $k2=>&$v2)
				{
					//对部门处理 -- 数组 
					$v2['fdanweibumen'] = explode(',',$v2['fdanweibumen']);
					//$v2['fisgongshijs'] = explode(',',$v2['fisgongshijs']);
					
				}
			}
			
		}
		
		showMsg(0,'成功' , $result) ;
		
		
		
	}
		
	/**
	* 获取 加账   
	* @date: 2023年2月16日 下午7:07:41
	* @author: juyi
	*/
	public function FJZModel(Request $request){
		$fmodel = $request->fmodel ; 
		$FRepKey = $request->get('FRepKey');
		$opername = $request->get('opername'); //当前登录人名称      '测试3'
		$fdanweibumen = $request->get('fdanweibumen'); //部门
		
		
		$fkeywordStr  = "" ;
		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
			$keyword = $request->keyword  ;
			$fkeywordStr=" and ( charindex('{$keyword}',u1.fname)>0  or  charindex('{$keyword}',v1.fprodno)>0 or  charindex('{$keyword}',u1.fcode)>0  )" ;
		}
		
		if( in_array($FRepKey, [ '26005', '26023','26025',   ]) ) {
			$bumenStr = "";
			if($request->fdanweibumen  == 1){
				//采购部
				$bumenName ="采购";
				$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0   )" ;
				
			}elseif($request->fdanweibumen  == 2){
				//技术中心
				$bumenName ="技术";
				$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0   )" ;
			}elseif($request->fdanweibumen  == 3){
				//其他部门    =  售后服务部、生产管理部  ， 质量管理部
				$bumenName ="售后";
				$bumenName1 ="生产";
				$bumenName2 ="质量";
				$bumenName3 ="其他";
				$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0  or charindex('{$bumenName1}',u1.fdanweibumen)>0 or charindex('{$bumenName2}',u1.fdanweibumen)>0 or charindex('{$bumenName3}',u1.fdanweibumen)>0  )" ;
			}
			
			$baseSql =" select v1.fid,u1.fbrand,v1.fcode,v1.fprodno ,u1.fname,u1.fdanweibumen,v1.fallAmount,
			v1.fstatus   from gz_YjiazhangcbfMX v1 left join gz_YjiazhangcbfSet u1 on u1.fcode=v1.fcode 
			where 1=1 and v1.fprodno ='{$fmodel}'  {$fkeywordStr}  {$bumenStr} order by v1.fcode  " ;
		}
		
		if(in_array($FRepKey, [ '26009', '26022'   ])  ){
			$baseSql =" select v1.fid,v1.fbrand,v1.fcode,v1.fprodno ,u1.fname,u1.fdanweibumen,
		v1.fallAmount,v1.fstatus from gz_Ycaigoucbf v1 left join gz_YcaigoucbfSet u1 on u1.fcode=v1.fcode
		where 1=1 and v1.fprodno ='{$fmodel}'  {$fkeywordStr} order by v1.fcode   " ;
		}
// 		echo $baseSql;die;
		$res = SqlServerUtil::execTosqlOK($this->SqlServer,  $baseSql);
		$result =[];
		if($res){
			$result = arraykeyToLower($res);
			foreach ($result as $k1=>&$v1)
			{
				foreach ($v1 as $k2=>$v2)
				{
					if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
						$v1[$k2] = floatval($v2);
					}
					// fnbfhyx
				}
			}
		}
		showMsg(0,'成功' , $result) ;
	}
	
	/**
	* 文件用途描述
	* @date: 2023年2月16日 下午7:12:47
	* @author: juyi
	*/
	public function FJZEdit(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername= $request->get('opername');
		$data =  $request->all() ;
		$insertRecords = $data['insertRecords'];
		$updateRecords = $data['updateRecords'];
		$removeRecords = $data['removeRecords'];
		if(empty($insertRecords) && empty($updateRecords)  && empty($removeRecords)  ){
			showMsg(400,'数据修改为空');
		}
		$temp = [];
		if( in_array($FRepKey, [ '26005', '26023','26025',   ]) ) {
			//加账清单 
			$db ="gz_YjiazhangcbfMX" ;
		}
		if(in_array($FRepKey, [ '26009', '26022'   ])  ){
			//采购
			$db ="gz_Ycaigoucbf";
		}
		
		//新增
		if(!empty($insertRecords)){
			$aa =array_column($data['data'] ,'fcode') ;
			if(count($aa) != count(array_unique($aa ))){
				showMsg(400,'新增有重复值 ，无法保存！');
			}
			//判断当前代码是否已存在
			$tmpfcode = array_column($insertRecords, 'fcode');
			$Modelone = array_unique($tmpfcode)  ;
			// 	 		dd($one ,array_column($insertRecords, 'fprodno') );
			if(count($Modelone) != count($tmpfcode) ){
				showMsg(400, ' fcode有多个，支持唯一fcode');
			}
			
		    //判断机型
			$fprodnoArr = array_column($data['data'], 'fprodno') ;
			$fprodnoone = array_unique($fprodnoArr)  ;
			$fprodnoArrTwo = array_column($insertRecords, 'fprodno');
			$fprodnoTwo = array_unique($fprodnoArrTwo)  ;
			if(count($fprodnoone) != count($fprodnoTwo) ){
				showMsg(400, ' 机型型号是否 正确，请检查');
			}
			
			//字符串
			$fmodel =join("','", $fprodnoTwo);
			$fmodelStr = "'".$fmodel ."'";
			$sql =" select fmodel from gz_YBaseJS where fmodel in ({$fmodelStr}) ";
			$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
			if(empty($SetCodeData)){
				showMsg(400,'该机型不存在，请联系技术中心 ');
			}
			if(count($SetCodeData) != count($fprodnoTwo) ){
				showMsg(400, ' 机型型号是否 正确，请检查');
			}
			
			foreach ($insertRecords as $kup=>&$vup)
			{
				if(empty($vup['fprodno']) || empty($vup['fcode']) || empty($vup['fbrand'])){
					showMsg(400,'请输入机型或代码或品牌');
				}
				unset($insertRecords[$kup]['fname']) ;
				unset($insertRecords[$kup]['_X_ROW_KEY']) ;
			}
			
			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insertRecords);
			
			$this->writeLog(getMkName($FRepKey),'新增 ' , $FRepKey , $insertRecords ,$opername);
			
		}
		if(!empty($updateRecords)){
			//判断当前机型是否已存在
			$tmpfcode = array_column($updateRecords, 'fcode');
			$Modelone = array_unique($tmpfcode)  ;
			// 	 		dd($one ,array_column($insertRecords, 'fmodel') );
			if(count($Modelone) != count($tmpfcode) ){
				showMsg(400, ' fcode有多个，支持唯一fcode');
			}
			//判断机型
			$fprodnoup = array_column($data['data'], 'fprodno') ;
			$fprodnoUpone = array_unique($fprodnoup)  ;
			$fprodnoArrTwo = array_column($updateRecords, 'fprodno');
			$fprodnoUpTwo = array_unique($fprodnoArrTwo)  ;
			if(count($fprodnoUpone) != count($fprodnoUpTwo) ){
				showMsg(400, ' 机型型号是否 正确，请检查');
			}
			
			//字符串
			$fmodel =join("','", $fprodnoUpTwo);
			$fmodelStrUp = "'".$fmodel ."'";
			$sql =" select fmodel from gz_YBaseJS where fmodel in ({$fmodelStrUp}) ";
			$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
			if(empty($SetCodeData)){
				showMsg(400,'该机型不存在，请联系技术中心 '); 
			}
			if(count($SetCodeData) != count($fprodnoUpTwo) ){
				showMsg(400, ' 机型型号是否 正确，请检查');
			}
			
			// 修改
			foreach ($updateRecords as $kup=>&$vup)
			{
				if(empty($vup['fprodno']) || empty($vup['fcode'])){
					showMsg(400,'请输入机型或代码');
				}
				$insData =[];
				$where = [];
				$where = ['fid'=>$vup['fid']];
				$insData['fallamount'] = $vup['fallamount'];
				 
				unset($updateRecords[$kup]['fid']) ;
				unset($updateRecords[$kup]['fname']) ;
				unset($updateRecords[$kup]['_X_ROW_KEY']) ;
				SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
				//SqlServerUtil::exeupdateTosql($this->SqlServer,$db.'Set',['ffaxAmount'=>$vup['fallamount']],['fcode'=>$vup['fcode'] ]);
				$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $vup ,$opername );
			}
			
		}
		
		if(!empty($removeRecords)){
			// 删除
			$Fids =[];
			$Fids = join("','", array_column($removeRecords, 'fid'));
			SqlServerUtil::sqlsrvDelete($this->SqlServer,$db, ['fid'=>"'".$Fids ."'" ],true);
			$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $removeRecords ,$opername );
		}
		
		showMsg(200 );
	}
	
	/**采购 加账  -- 基础设置
	 * 新增  -- 保存 
	*  --------------- 
	* 采购成本  -- 基础新增  26009  ， 26022 
	* @date: 2023年4月6日 下午3:18:33
	* @author: juyi
	*/
	public function FJZSave(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername= $request->get('opername');
		$data =  $request->all() ;
		$insertRecords = $data['insertRecords'];
		$updateRecords = $data['updateRecords'];
		$removeRecords = $data['removeRecords'];
		if(empty($insertRecords) && empty($updateRecords)  && empty($removeRecords)  ){
			showMsg(400,'数据修改为空');
		}
		$fbrand = $request->fbrand ;
		$temp = [];
		if( in_array($FRepKey, [ '26005', '26023','26025',   ]) ) {
			//加账
			$db ="gz_YjiazhangcbfSet" ;
			//$db1 ="gz_YjiazhangcbfMX" ;
			if(  $request->fbrand == 'WINGD'){
				$Jzbrand = 'JZW';
				$jzfcode = 'JZW001';
			}else{
				$Jzbrand = 'JZM';
				$jzfcode = 'JZM001';
			}
		}
		if(in_array($FRepKey, [ '26009', '26022'   ])  ){
			//采购
			$db ="gz_YcaigoucbfSet";
			//CGM
			//$db1 ="gz_YcaigoucbfMX";
		}
		$fbrand = strtoupper(str_replace(' ','',$fbrand));
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$ins = true;
		$upd = true;
		//新增
		if(!empty($insertRecords)){
			//这里处理一下数据倒置问题
			$insertRecords = array_reverse($insertRecords);
			foreach ($insertRecords as $kup=>&$vup)
			{
				
				if(in_array($FRepKey, [ '26009'  ])){
					$CGbrand = 'CGW';
					$vup['fbrand'] ='WINGD' ;
					$vup['fdanweibumen'] ='采购部' ;
					$tt = SqlServerUtil::execToSql($this->SqlServer,"select max(RIGHT(fcode,3)) as nums from gz_YcaigoucbfSet  where fbrand  = 'WINGD' ",2);
					if($tt){
						$jzfcode = $CGbrand. str_pad(intval($tt['nums'])+1+$kup, 3,'0',STR_PAD_LEFT);
					}
					$vup['fcode'] = $jzfcode;
				}
				if(in_array($FRepKey, [ '26022'  ])){
					$CGbrand = 'CGM';
					$vup['fbrand'] ='MAN' ;
					$vup['fdanweibumen'] ='采购部' ;
					$tt = SqlServerUtil::execToSql($this->SqlServer,"select max(RIGHT(fcode,3)) as nums from gz_YcaigoucbfSet  where fbrand  = 'MAN' ",2);
					if($tt){
						$jzfcode = $CGbrand. str_pad(intval($tt['nums'])+1+$kup, 3,'0',STR_PAD_LEFT);
					}
					$vup['fcode'] = $jzfcode;
				}
				
				//下面是加账信息
				if(in_array($FRepKey, [ '26005'  ])){
					//加账清单(采购)  26005
					$vup['fbrand'] = $request->fbrand ;
					$tt = SqlServerUtil::execToSql($this->SqlServer,"select max(RIGHT(fcode,3)) as nums from gz_YjiazhangcbfSet  where fbrand  = '{$request->fbrand }' ",2);
					if($tt){
						$jzfcode = $Jzbrand. str_pad(intval($tt['nums'])+1+$kup, 3,'0',STR_PAD_LEFT);
					 }
					$vup['fcode'] = $jzfcode;
					$vup['fdanweibumen'] = empty($vup['fdanweibumen'])? ['采购部']:$vup['fdanweibumen'] ;
					$vup['fdanweibumen'] = join(',', $vup['fdanweibumen'])   ;
					
				}
				if(in_array($FRepKey, [ '26023'  ])){
					//加账清单(技术)  26023 
					$vup['fbrand'] = $fbrand ;
					$tt = SqlServerUtil::execToSql($this->SqlServer,"select max(RIGHT(fcode,3)) as nums from gz_YjiazhangcbfSet  where fbrand  = '{$request->fbrand }' ",2);
					if($tt){
						$jzfcode = $Jzbrand. str_pad(intval($tt['nums'])+1+$kup, 3,'0',STR_PAD_LEFT);
					}
					$vup['fcode'] = $jzfcode;
					if(empty($vup['fdanweibumen'])){
						showMsg(400,'部门不能为空，请选择');
					}
					$vup['fdanweibumen'] = join(',', $vup['fdanweibumen'])   ;
				}
				if(in_array($FRepKey, [ '26025'  ])){
					//加账成本(其他)   26025 
					$vup['fbrand'] = $fbrand ;
					$tt = SqlServerUtil::execToSql($this->SqlServer,"select max(RIGHT(fcode,3)) as nums from gz_YjiazhangcbfSet  where fbrand  = '{$request->fbrand }' ",2);
					if($tt){
						$jzfcode = $Jzbrand. str_pad(intval($tt['nums'])+1+$kup, 3,'0',STR_PAD_LEFT);
					}
					$vup['fcode'] = $jzfcode;
					//$vup['fdanweibumen'] ='其他部' ;
					if(empty($vup['fdanweibumen'])){
						showMsg(400,'部门不能为空，请选择');
					}
					$vup['fdanweibumen'] = join(',', $vup['fdanweibumen'])   ;
				}
				 
				unset($insertRecords[$kup]['_X_ROW_KEY']) ;
				
			}
			
			$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insertRecords);
			
		}
		if(!empty($updateRecords)){
			//参数值
			$CsData =  $this->getSystemProfile('FSetJiaZhangSX');
			if(!empty($CsData['fsetjiazhangsx']) && $CsData['fsetjiazhangsx'] ==1){
				showMsg(400,'基础信息代码不能修改');
			}
			
			// FSetJiaZhangSX 设置为 0  ，有条件修改 
			//加账成本
			//判断正式报价 是否存在 fcode 代码 已使用情况
			$arrTT = array_column($updateRecords, 'fcode');
			//fcode 是否存在 正式 报价里
			$fcode =join("','", $arrTT);
			$fcodeStr = "'".$fcode ."'";
			if(!empty($CsData['fsetjiazhangsx']) && $CsData['fsetjiazhangsx'] == 2){
				if(in_array($FRepKey, [ '26005' ,'26023','26025'  ])){
					$sql = "select fprodno from gz_Yjiazhangcbf_BAOJIA  where 1=1 and fcode  in ({$fcodeStr}) group by fprodno "  ;
					$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
					if($SetCodeData){
						showMsg(400,'正式报价列表中代码已存在，使用中，无法修改!');
					}
					//判断 代码是否已经存在
					$sql = "select fprodno from gz_YjiazhangcbfMX where 1=1 and fcode  in ({$fcodeStr})  group by fprodno" ;
					$SetCodeDataJZ = SqlServerUtil::execToSql($this->SqlServer,$sql);
					if(!empty($SetCodeDataJZ)){
						showMsg(400,'代码已存在加账成本中，无法修改!');
					}
				}
				//采购成本 
				if(in_array($FRepKey, [ '26009' ,'26022'  ])){
					//判断 代码是否已经存在
					$sql = "select fprodno from gz_Ycaigoucbf where 1=1 and fcode  in ({$fcodeStr}) group by fprodno " ;
					$SetCodeDataCG = SqlServerUtil::execToSql($this->SqlServer,$sql);
					if(!empty($SetCodeDataCG)){
						showMsg(400,'代码已存在使用中，无法修改!');
					}
					//经营报价
					$sql = "select fprodno from gz_Ycaigoucbf_ZLCCG where 1=1 and fcode  in ({$fcodeStr}) group by fprodno " ;
					$JYCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
					if(!empty($JYCodeData)){
						showMsg(400,'经营报价列表中代码已存在，使用中，无法修改!');
					}
					//正式报价
					$sql = "select fprodno from gz_Ycaigoucbf_BAOJIA where 1=1 and fcode  in ({$fcodeStr}) group by fprodno " ;
					$ZSCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
					if(!empty($ZSCodeData)){
						showMsg(400,'正式报价列表中代码已存在，使用中，无法修改!');
					}
				}
			}
			
			// 修改
			foreach ($updateRecords as $kup=>&$vup)
			{
				//
				$insData =[];
				$where = [];
				$where = ['fid'=>$vup['fid']];
// 				unset($updateRecords[$kup]['fqty']) ;
// 				unset($updateRecords[$kup]['ffaxamount']) ;
// 				unset($updateRecords[$kup]['fzjqty']) ;
				if(in_array($FRepKey, [ '26009' ,'26022'  ])){
					$vup['fdanweibumen'] ='采购部';
				}
				if(in_array($FRepKey, [ '26005' ,'26023','26025'    ])){
					$vup['fdanweibumen'] = join(',', $vup['fdanweibumen'])   ;
				}
				unset($updateRecords[$kup]['fid']) ;
				unset($updateRecords[$kup]['_X_ROW_KEY']) ;
				
				unset($vup['fcode']); // code代码不能更新
				//dd($vup);
				$upd = SqlServerUtil::exeupdateTosql($this->SqlServer,$db ,$vup,$where );
			}
		}
		
		if(!empty($removeRecords)){
			// 删除
			$Fids =[];
		//	$Fids = join("','", array_column($removeRecords, 'fid'));
// 			SqlServerUtil::sqlsrvDelete($this->SqlServer,$db, ['fid'=>"'".$Fids ."'" ],true);
		}
		
		if($ins && $upd  ){
			sqlsrv_commit($this->SqlServer);
			showMsg(0,'成功');
		}else {
			sqlsrv_rollback($this->SqlServer);
			showMsg(1,'失败');
		}
		 
	}
	
	 
	//  基础设置  -- 
	public function FSetBaseSave(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername= $request->get('opername');
		$data =  $request->all() ;
		$insertRecords = $data['insertRecords'];
		$updateRecords = $data['updateRecords'];
		$removeRecords = $data['removeRecords'];
		if(empty($insertRecords) && empty($updateRecords)  && empty($removeRecords)  ){
			showMsg(400,'数据修改为空');
		}
		$temp = [];
		if( in_array($FRepKey, [ '26005', '26023','26025',   ]) ) {
			//加账
			$db ="gz_YjiazhangcbfSet" ;
			//$db1 ="gz_YjiazhangcbfMX" ;
		}
		if(in_array($FRepKey, [ '26009', '26022'   ])  ){
			//采购
			
			$db ="gz_YcaigoucbfSet";
			//$db1 ="gz_YcaigoucbfMX";
		}
		 $fbrand =  strtoupper(str_replace(' ','',$request->fbrand));
		//新增
		if(!empty($insertRecords)){
			foreach ($insertRecords as $kup=>&$vup)
			{
				// 				unset($insertRecords[$kup]['fname']) ;
				if(in_array($FRepKey, [ '26009'  ])){
					$vup['fbrand'] ='WINGD' ;
					$vup['fdanweibumen'] ='采购部' ;
					
				}
				if(in_array($FRepKey, [ '26022'  ])){
					$vup['fbrand'] ='MAN' ;
					$vup['fdanweibumen'] ='采购部' ;
				}
				
				if(in_array($FRepKey, [ '26005'  ])){
					$vup['fbrand'] = $fbrand ;
					$vup['fdanweibumen'] ='采购部' ;
					
				}
				if(in_array($FRepKey, [ '26023'  ])){
					$vup['fbrand'] = $fbrand ;
					$vup['fdanweibumen'] ='技术部' ;
				}
				if(in_array($FRepKey, [ '26025'  ])){
					$vup['fbrand'] = $fbrand ;
					
				}
				
				unset($insertRecords[$kup]['_X_ROW_KEY']) ;
			}
			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insertRecords);
			
		}
		if(!empty($updateRecords)){
			// 修改
			foreach ($updateRecords as $kup=>&$vup)
			{
				$insData =[];
				$where = [];
				$where = ['fid'=>$vup['fid']];
				unset($updateRecords[$kup]['fid']) ;
				unset($updateRecords[$kup]['_X_ROW_KEY']) ;
				
				SqlServerUtil::exeupdateTosql($this->SqlServer,$db ,$vup,$where );
			}
		}
		
		if(!empty($removeRecords)){
			// 删除
			$Fids =[];
			$Fids = join("','", array_column($removeRecords, 'fid'));
			SqlServerUtil::sqlsrvDelete($this->SqlServer,$db, ['fid'=>"'".$Fids ."'" ],true);
			
		}
		
		showMsg(200 );
	}
	
	
	/**
	* 文件用途描述
	* @date: 2023年3月2日 下午3:48:47
	* @author: juyi
	*/
	public function FBaseCGJZModel(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername= $request->get('opername');
		$fmodel = $request->get('fmodel');
		$fbrand = $request->get('fbrand');
		$fbrand = strtoupper(str_replace(' ','',$fbrand));
		
		$data =  $request->all() ;
		$fgenderData = SqlServerUtil::execToSql($this->SqlServer,"select fbrand ,fmodel from gz_YBaseJS where   fbrand  = '{$fbrand}'  and fmodel not in (
		select fprodno from gz_Ycaigoucbf where 1=1 and  fbrand  = '{$fbrand}'  group by fprodno) " );
		if($fgenderData){
			showMsg(200,'成功',$fgenderData );
		}
		showMsg(200,'成功',$fgenderData );
	}
	
	/**
	* 采购 新增 保存 
	* @date: 2023年3月2日 下午4:34:16
	* @author: juyi
	*/
	public function FCGCBSave(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername= $request->get('opername');
		$data =  $request->all() ;
		$insertRecords = $data['data'];
		$fmodel = $request->get('fmodel');
		$fbrand = $request->get('fbrand')??'WINGD';
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		if(empty($insertRecords)   ){
			showMsg(400,'数据为空,请选择一行勾选');
		}
		if(empty($fmodel)){
			showMsg(400,'机型为空或已添加 在原机型修改，请选择一个机型');
		}
		$temp = [];
		if( in_array($FRepKey, [ '26005', '26023','26025',   ]) ) {
			//加账
			$db ="gz_Yjiazhangcbf" ;
			 
		}
		
		if(in_array($FRepKey, [ '26009', '26022'   ])  ){
			$fbrand = 'WINGD';
			if($FRepKey == '26022'){
				$fbrand = 'MAN';
			 } 
			 $db ="gz_Ycaigoucbf" ;
			//采购
			$cgData= [];
			foreach ($insertRecords as $kup=>&$vup)
			{
				$cgData[$kup]['fbrand'] = strtoupper(str_replace(' ','',$fbrand)); 
				$cgData[$kup]['fprodno'] = $fmodel;
				$cgData[$kup]['fcode']= $vup['fcode'] ; 
				$cgData[$kup]['fallAmount']= $vup['ffaxamount'] ;
			}
			$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fprodno'=> "'".$fmodel."'" ],true);
			$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $cgData);
			$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
			
			if($ins  ){
				sqlsrv_commit($this->SqlServer);
				showMsg(0,'成功');
			}else {
				sqlsrv_rollback($this->SqlServer);
				showMsg(1,'失败');
			}
			
		} 
		
		
		showMsg(200 );
	}
	
	
	/**
	* 文件用途描述
	* @date: 2023年3月2日 下午6:55:39
	* @author: juyi
	*/
	 function FImportCG(Request $request){
		$FRepKey = $request->get('FRepKey');
		$opername= $request->get('opername');
		$data =  $request->all() ;
		
		$insertRecords = $data['data'];
		$fbrand = 'WINGD';
		if($FRepKey == '26009'){
			$fbrand = 'WINGD';
			$SuBCG = 'W';
		}elseif($FRepKey == '26022'){
			$fbrand = 'MAN';
			$SuBCG = 'M';
		} 
		
		// 启动事务
		if (sqlsrv_begin_transaction($this->SqlServer) === false) {
			die(print_r(sqlsrv_errors(), true));
		}
		$db =columnBiao($FRepKey);
		if(!empty($insertRecords)){
			//判断当前机型是否已存在
			$fprodno= $insertRecords[0]['fmodel'];
			$one = array_unique(array_column($insertRecords, 'fmodel'))  ;
			if(count($one) >1  ){
				showMsg(400, ' 机型只支持一个机型导入'); 
			}
			
			$arrTT = array_column($insertRecords, 'fcode'); 
			if($FRepKey == '26009' || $FRepKey == '26022' ){
				foreach ($arrTT as $fv)
				{
					if(subStr($fv,2,1) != $SuBCG ){
						showMsg(400, ' 导入信息有误不在当前页面');
					}
				}
			}
			//机型 JS 是否有 判断
			$sql = "select  fbrand ,fmodel,fpower  from gz_YBaseJS where fmodel ='{$fprodno}' " ;
			$TempDataJS = SqlServerUtil::execToSql($this->SqlServer,$sql);
			if(empty($TempDataJS)){
				showMsg(400, '技术中心不存在这个机型:'.$fprodno.'，请确认');
			}
			
			
			//fcode  是否存在 设置里
			$fcode =join("','", $arrTT);
			$fcodeStr = "'".$fcode ."'";
			$sql = "select fid, fcode from gz_Ycaigoucbfset where 1=1 and fcode  in ({$fcodeStr})" ;
			$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
			if($SetCodeData){
				$arr2 = array_column($SetCodeData, 'fcode');
				$arrayDiff = array_diff($arrTT ,$arr2 ) ;
				if($arrayDiff){
					showMsg(400, join(',',$arrayDiff).' 导入代码不存在，请联系采购或技术');
				}
			}
			
			// and fcode  in ({$fcodeStr})
			$sql = "select fid,fbrand ,fcode,fprodno,fstatus from gz_Ycaigoucbf where fprodno='{$fprodno}' and fcode  in ({$fcodeStr})" ;
// 			echo $sql ;die;
			$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
			if(in_array(1,array_unique(array_column($TempData, 'fstatus')))){
				showMsg(400,$fprodno.'当前已审核，无法导入');
			}
			$insert1=false;
			$update=false;
			$insert2 =false;
			
			$cgData =[];
			$arr =[]; 
			if($TempData){
// 				dd($insertRecords);
				/* "fcode" => "CGW015"
				"fname" => "油雾探测器"
				"fmodel" => "6RT-flex58T-E"
				"famount" => 15
				"fremark" => null
				"_X_ROW_KEY" => "row_198" */
				//存在
// 				dd($TempData);
				foreach ($insertRecords as $ls =>&$lsVal){
					unset($lsVal['_X_ROW_KEY']) ; 
					unset($lsVal['fstatus']) ; 
					unset($lsVal['fname']) ; 
					$lsVal['fprodno'] = $lsVal['fmodel'];
					unset($lsVal['fmodel']) ; 
					$lsVal['fallAmount'] = $lsVal['famount'];
					unset($lsVal['famount']) ; 
					unset($lsVal['fremark']) ; 
					$lsVal['fbrand'] =  strtoupper(str_replace(' ','',$fbrand));
					
					foreach ($TempData as $itemkey=>$itemVal){
						if($lsVal['fprodno'] == $itemVal['fprodno'] && $lsVal['fcode'] == $itemVal['fcode'])
						{
							$arr[$ls]['fid'] =   $itemVal['fid'];
							//存在
							$arr[$ls]['fbrand'] = $fbrand;
							$arr[$ls]['fprodno'] =  $lsVal['fprodno'] ;
							$arr[$ls]['fcode']= $lsVal['fcode'] ;
							$arr[$ls]['fallAmount']= $lsVal['fallAmount'] ;
							 
							unset($insertRecords[$ls]);
						}
					}
				}
// 				dd( $arr , $insertRecords);
				$insert1=true;
				$update=true;
				if($insertRecords && count($insertRecords)>0){
					$insert1=SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db, $insertRecords);
				}
				if($arr && count($arr)>0){
					//dd($arr);
					$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer, $db, $arr);
				}
				
			}else{
				//无全部导入
				foreach ($insertRecords as $kup=>&$vup)
				{
					if(empty($vup['fcode']) || empty($vup['fmodel']) ){
						showMsg(400, ' 导入数据'.$vup['fname'].'机型或代码为空' );
					}
					$cgData[$kup]['fbrand'] =   strtoupper(str_replace(' ','',$fbrand));
					$cgData[$kup]['fprodno'] =  $vup['fmodel'] ;
					$cgData[$kup]['fcode']= $vup['fcode'] ;
					$cgData[$kup]['fallAmount']= $vup['famount'] ;
					// 				$cgData[$kup]['fnote']= $vup['fremark'] ;
				}
// 				$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fprodno'=>   "'".$fprodno."'"  ],true);
				$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $cgData);
				$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
				
			}
			if(($insert1 && $update) || $insert2  ){
				sqlsrv_commit($this->SqlServer);
				showMsg(0,'成功');
			}else {
				sqlsrv_rollback($this->SqlServer);
				showMsg(1,'失败');
			}
			
			
		}else{
			showMsg(1,'数据信息为空');
		}
		
	 }
	 
	 
	 /**
	 * 业务部门导入加账 
	 * @date: 2023年3月2日 下午7:40:44
	 * @author: juyi
	 */
	 function FYWImportJZ(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$fmodel = $request->get('fmodel');
	 	$fbrand = $request->get('fbrand') ;
	 	$fbillno = $request->get('fbillno') ;
	 	$rows = $request->get('rows') ;
	 	$insertRecords = $data['data'];
// 	 	加账清单(采购)   26005
// 	 	加账清单(技术)  26023
// 	 	加账成本(其他)   26025
	 	if(empty($fmodel)  || empty($fbillno)){
	 	 	showMsg(400,'机型 参数错误');
	 	 }
	 	 if(empty($rows)){
	 	 	showMsg(400,'当前行未选中');
	 	 }
	 	 
	 	 //判断是否有加账
	 	 if( $rows['fisjiazhang'] == '否'){
	 	 	showMsg(400,'当前信息列表选择加账为否，无法导入加账 请检查！');
	 	 }
	 	 
	 	 $sxqty = $rows['fqty'] ;
	 	 $sql = "select fbrand  from gz_Ybasejs where  fmodel='{$fmodel}'  " ;
	 	 $jsData = SqlServerUtil::execToSql($this->SqlServer,$sql,2);
	 	 
	 	 if(empty($jsData)){
	 	 	showMsg(400, $fmodel.' 机型对应品牌不存在，请检验，');
	 	 }
	 	 $fbrand = strtoupper(str_replace(' ','', $jsData['fbrand'])) ;
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	if($FRepKey == '14009'){
	 		$db = 'gz_Yjiazhangcbf';
	 		$db14009 ='gz_YBaseSC';
	 	}
	 	if($FRepKey == '34001'){
	 		$db = 'gz_Yjiazhangcbf_HXJZ';
	 		$db14009 ='gz_YBaseSC_HXJZ';
	 		
	 		$fbillnoentry = $rows['fbillnoentry'] ;
	 	}
	 	
	 //	$cs = $this->getSystemProfile(['fsetZhuangShiRGprice','FSetRGzhuangshiCJPrice' ,'FSetFFAX' ,'FSetChaiYouPrice' ,'FSetQiGangPrice' ,'FSetRanqiPrice' , ]);
	 	
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$arr1 = array_column($insertRecords, 'fcode');
	 		$fcode =join("','", $arr1);
	 		$fcodeStr = "'".$fcode ."'";
	 		if($rows['fisscr'] !='否'){
	 			if(strtolower($rows['fisscr']) == 'iscr' ){  
	 				if( !isValueInArrayiSCR($insertRecords,'iSCR')  ){
	 					showMsg(400,'加账清单没有选择带iSCR  ，或加账清单基础设置没添加，请检查 ');
	 				}
	 			}else{
	 				//清单 必有
	 				if( !isValueInArrayICER($insertRecords, 'PSCR' )  ){
	 					showMsg(400, ' 业务需求 选择`是否含SCR`,与加账清单 SCR高低硫 不一致 , 请检查 ');
	 				}
	 				
	 				if( $rows['fisscr'] ==  "LPSCR"){
	 					if( !isValueInArrayICER($insertRecords, 'LPSCR' )  ){
	 						showMsg(400, '   业务需求 选择`是否含SCR`,与加账清单 LPSCR高低硫 不一致 , 请检查 ');
	 					}
	 				}
	 				if( $rows['fisscr'] ==  "HPSCR"){
	 					if( !isValueInArrayICER($insertRecords, 'HPSCR' )  ){
	 						showMsg(400, '   业务需求 选择`是否含SCR`,与加账清单 HPSCR高低硫 不一致 , 请检查 ');
	 					}
	 				}	
	 				
// 		 			$fcodeTmp = isHPLPSCRONE($fbrand , $arr1) ;  
// 		 			if( $fcodeTmp=== true){
// 		 				showMsg(400,  'SCR高低硫选择不正确，请检查0 ');
// 		 			}
// 		 			if(isHPLPSCR($fbrand , strtoupper($fcodeTmp) ,$rows['fisscr'],$rows['fscrlowup'] )){
// 		 				showMsg(400,  'SCR高低硫是否正确，请检查1 ');
// 		 			}
	 			}
	 		}
	 		
	 		// 判断 高硫  3.5%   如果硫含量3.5%，把LDCL系统的成本自动放在主机成本总价里。
	 		if($FRepKey != '34001'){
    	 		if($fbrand == 'MAN'){
    	 			if( stripos( $rows['fzhujiranliaos'] , '3.5' ) !== false){
    	 				if(!in_array('JZM028', $arr1)){
    	 					showMsg(400, '硫含量'.$rows['fzhujiranliaos']. ',LDCL系统未添加，请检查');
    	 				}
    	 			}
    	 		}
	 		}
	 		//加账选了ICER , 必须在市场部报价格式里面ICER不能选无   
	 		if($FRepKey == '14009'){
	 			// 甲醇机项目在市场部需求环节，是否含EGR，选择不能为否。且加账清单需要有EGR或者ECOEGR
// 	 			if( stripos( strtoupper($rows['fmodel']) , 'LGIM' ) !== false)    {
// 	 				if( !isValueInArrayICER($insertRecords,'EGR')  ){
// 	 					showMsg(400,'加账清单没有选择带EGR  ，或加账清单基础设置没添加，请检查 ');
// 	 				}
// 	 			}
	 			
	 			//有ICER 
	 			if( $rows['fegcmodel'] !='无' ){
	 				$fegcmodelICER = 'EGC'.$rows['fegcmodel'];
	 				if( !isValueInArrayICER($insertRecords,$fegcmodelICER)  ){
	 					showMsg(400,'加账清单没有选择ICER ('.$fegcmodelICER .')，或加账清单基础设置没添加，请检查 ');
	 				}
	 			}
	 			
	 			if( $rows['fegcmodel'] =='无' || empty($rows['fegcmodel']) ){
	 				$fegcmodelICER_0 = 'EGC' ;
	 				if( isValueInArrayICER($insertRecords,$fegcmodelICER_0)  ){
	 					showMsg(400,'加账清单含有ICER 与  业务需求市场部信息选择EGC型号不一致  ，请检查 ');
	 				}
	 			}
	 		}
	 		
	 		//判断导入代码是否在 加账设置里
	 		$sql = "select fid,fcode,fqty,ffaxAmount from gz_YjiazhangcbfSet where  fcode  in ({$fcodeStr}) and  fbrand = '{$fbrand}' " ;
	 		$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if(empty($TempData)){
	 			showMsg(400,'当前品牌'.$fbrand.'导入品牌对应代码是否正确');
	 		}
	 		if($TempData){
	 			$arr2 = array_column($TempData, 'fcode');
	 			$arrayDiff = array_diff($arr1 ,$arr2 ) ;
	 			if($arrayDiff){
	 				showMsg(400, join(',',$arrayDiff).' 导入代码不存在，请联系采购或技术');
	 			}
	 		}
	 		
	 		$cgData =[];
	 		foreach ($insertRecords as $kup=>&$vup)
	 		{
	 			////导入校验 是否是高低硫 
	 			$faxamount =  0 ; 
	 			if(empty($vup['fcode']) ){
	 				showMsg(400, ' 导入数据'.$vup['fname'].' 代码为空，请确认' );
	 			}
	 			if(empty($vup['fqty']) ){
	 				showMsg(400, ' 导入数据'.$vup['fname'].' 数量为0，请检查' );
	 			}
	 			
	 			$cgData[$kup]['fbrand'] =   $fbrand ;
	 			$cgData[$kup]['fbillno'] = $rows['fbillno'] ;
	 			if($FRepKey == '34001'){
	 				$cgData[$kup]['fbillnoentry'] = $rows['fbillnoentry'] ;
	 			}
	 			$cgData[$kup]['fprodno'] =  $rows['fmodel'] ;
	 			$cgData[$kup]['fcode']= $vup['fcode'] ; 
	 			$cgData[$kup]['fywQty']= $vup['fqty'] ;
	 			$cgData[$kup]['fnote']= isset($vup['fnote'])?$vup['fnote']:"" ;
	 			$cgData[$kup]['fallAmount']= arrayFilterFieldValue($TempData,'fcode',$vup['fcode'])[0]['ffaxAmount']  ;
	 			
	 		}
	 		//修改 加账
	 		$fidArr = array_column($TempData, 'fid');
	 		$jiazhangstr = join(',' , $fidArr);
	 		$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db14009, ['jiazhangdataStr'=>$jiazhangstr],['fid'=>$rows['fid'] ]);
	 		
	 		if($FRepKey == '14009'){
	 			$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fbillno'=>  "'".$fbillno."'"  ],true);
	 			$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $cgData);
	 		}elseif($FRepKey == '34001'){
	 			$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fbillnoentry'=>  "'".$fbillnoentry."'"  ],true);
	 			$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $cgData);
	 		}
	 		
	 		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
	 		if($ins && $u2 ){
	 			sqlsrv_commit($this->SqlServer);
	 			showMsg(0,'成功'  );
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}else{
	 		showMsg(1,'数据信息为空');
	 	}
	 	
	 }
	
	 
	 /**
	 * 文件用途描述
	 * @date: 2023年3月6日 上午11:24:32
	 * @author: juyi
	 */
	 function FImportGEN(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$isCheck= $request->get('ischeck')??0;
	 	
	 	$insertRecords = $data['data'];
	 	$fbrand = '';
	 	if($FRepKey == '26009'){
	 		$fbrand = 'WINGD';
	 	}elseif($FRepKey == '26022'){
	 		$fbrand = 'MAN';
	 	}
	 	$resMX = [];
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db =columnBiao($FRepKey);//数据库
	 	$insertRecords = arraykeyToLowerTo($insertRecords);
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$tmpModel = array_column($insertRecords, 'fmodel');
	 		$Modelone = array_unique($tmpModel)  ;
// 	 		dd($one ,array_column($insertRecords, 'fmodel') );
	 		if(count($Modelone) != count($tmpModel) ){
	 			showMsg(400, 'Excel 机型有多个,或重复机型，支持唯一机型导入');
	 		}
	 		$insert1=false;
	 		$update=false;
	 		$insert2 =false;
	 		$fmodelStr =join("','", $tmpModel );
	 		$fmodelStr = "'".$fmodelStr ."'";
	 		
	 		$sql = "select  fbrand ,fmodel,fpower,funit ,fmoli,fzhuansu ,fzzjweight,ffuliao as fdihao , fpackage as fbaozhuangwu,ffuliaopakeage  from gz_YBaseJS where fmodel in ({$fmodelStr}) " ;
	 		$TempDataJS = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if(empty($TempDataJS)){
	 			showMsg(400, '技术中心不存在这个机型，请确认1');
	 		}
	 		$arr2 = array_column($TempDataJS, 'fmodel');
	 		if(count($TempDataJS) !== count($tmpModel)){
	 			$arrayDiff = array_diff($tmpModel ,$arr2 ) ;
	 			if($arrayDiff){
	 				showMsg(400, join(',',$arrayDiff).' 技术中心不存在这个机型，请确认');
	 			}
	 		}
	 		
	 		//船检 机型 区分大小写
	 		//if(in_array($FRepKey,['26002','26002','26002','26002','26002','26002'])){
	 			foreach ($insertRecords as $mk=>$mv)
	 			{
	 				if(!in_array($mv['fmodel'],$arr2)  ) {
	 					showMsg(400,'该机型'.$mv['fmodel'].'与技术中心不一致(区分大小写)，请检查' );
	 				}
	 			}
	 			
	 		//}
	 		
	 		$cs = $this->getSystemProfile(['FSetHuiLv' ,'FSetFFAX' ,'fsetfucai535value','fsetfucai550value','fsetfucaibzw535value',
	 				'fsetfucaibzw550value','FSetFuCaiDWPrice' ,'FSetTuZhiSS','FSetYunBaoF','FSetChuanjianCCS' ,'FSetShuiDianjgcjPrice',
	 				'FSetProdFY' ]);
	 		$fexchangerate = 1;
	 		if($cs){
	 			$fexchangerate = $cs['fsethuilv'];
	 		}
	 		
	 		//辅材成本 28006  -- 机加工
	 		if(in_array($FRepKey,['28006'])){
	 			//生产部
	 			$ProdData =  SqlServerUtil::execToSql($this->SqlServer, " select  fdaojuxiaohao as fdaojufy, fmodel from gz_YBaseProduce  where fmodel  in ({$fmodelStr})  " );
	 			if(empty($ProdData)){
	 				showMsg(400,'生产部机型没有这个机型数据');
	 			}
	 			if(count($ProdData) !== count($tmpModel)){
	 				$prod2 = array_column($ProdData, 'fmodel');
	 				$arrayDiffProd = array_diff($tmpModel ,$prod2 ) ;
	 				if($arrayDiffProd){
	 					showMsg(400, join(',',$arrayDiffProd).'  生产部不存在这个机型，请确认');
	 				}
	 			}
	 			 
	 		}
	 		
	 		//获取字段
	 		$getVexTableColumnData = $this->getVexTableColumn($FRepKey ) ;
	 		foreach ($insertRecords as $k =>&$v)
	 		{
	 			foreach ($getVexTableColumnData as $kc=>$vc)
	 			{
	 				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='0' ) && $vc['freptype'] == 131 ){
	 					$v[$vc['frepfld']] =0;
	 				}
	 				
	 				if( !empty($v[$vc['frepfld']]) && $v[$vc['frepfld']]>0  && $vc['freptype'] == 131 ){
	 					$v[$vc['frepfld']] =round($v[$vc['frepfld']],$vc['fdecplaces']);
	 				}
	 				
	 				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
	 					$v[$vc['frepfld']] = '';
	 				}
	 				
	 				
	 				$resMX[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
	 				if(in_array($FRepKey,['14008' ,'14010','26016' ,'26013','26012','26011','28006','28007','26008' ])){
	 					$resMX[$k]['fbrand'] =  strtoupper(str_replace(' ','',$v['fbrand'] )) ;
	 				}
	 			
	 				
	 				if($FRepKey == '14010'){
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername;
	 					$resMX[$k]['fweiwaiamount'] =  round($v['fjuanyuan']+$v['flingxingjg']+$v['fsuanxilh']+$v['fjizuo']
	 							+$v['fjijia']+$v['fqita']+$v['fpaiyanguanzq']+$v['fzoutai']
	 							+$v['fgongzhuangjt']+$v['fbgrpaiyanguan']+$v['fbgrjinqi']+$v['fbgrzhengji'] ,2);
	 				}
	 				
	 				//船检费CCS
	 				if(in_array($FRepKey,['26002' ])){
	 					if($v['fchuanjishe'] !== 'CCS'){
	 						showMsg(400,'船社级不一致，请检查(是否是大写)');
	 					}
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername;
	 					$resMX[$k]['fchanjianfeiccs']  = round(($v['fzjjianyanf'] + $v['fnoxpaifangf']
	 							+ $v['flvtuf'] + $v['fjizuojijiaf']	+ $v['fzhusuf'] +   $v['fjiaotongf']
	 							+  $v['ftongxunf']  +  $v['fzhengshuf'])/$cs['fsetchuanjianccs'],2)   ;
	 				}
	 				
	 				//船检费ABS   25002
	 				if(in_array($FRepKey,['25002'])){
	 					if($v['fchuanjishe'] !== 'ABS'){
	 						showMsg(400,'船社级不一致，请检查(是否是大写)');
	 					}
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername;
	 					$resMX[$k]['fexchangerate'] = $fexchangerate;
	 					//整机检验费人民币
	 					$resMX[$k]['fzjjianyanfrmb'] =  round( $v['fzjjianyanf']*$fexchangerate ,2);
	 					//NOX排放费人民币
	 					$resMX[$k]['fnoxpaifangfrmb'] = round($v['fnoxpaifangf'] *$fexchangerate,2) ;
	 					//证书费人民币
	 					$resMX[$k]['fzhengshufrmb'] =  round($v['fzhengshuf'] *$fexchangerate ,2);
	 					//旅途时间费用人民币
	 					$resMX[$k]['flvtufrmb'] =  round( $v['flvtuf'] *$fexchangerate*30 ,2) ;
	 					
	 					$resMX[$k]['fchanjianfeiabs']  = round(($resMX[$k]['fzjjianyanfrmb'] + $resMX[$k]['fnoxpaifangfrmb']
	 							+ $resMX[$k]['fzhengshufrmb'] + $resMX[$k]['flvtufrmb']	+ $v['fzhusufrmb'] +   $v['franyoufrmb']
	 							+  $v['fguolufrmb'] +  $v['fhuosibutiermb']   ) ,2)   ;
	 					
	 				}
	 				//船检费LR   25003
	 				if(in_array($FRepKey,['25003'])){
	 					if($v['fchuanjishe'] !== 'LR'){
	 						showMsg(400,'船社级不一致，请检查(是否是大写)');
	 					}
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername;
	 					$resMX[$k]['fchanjianfeilr']  = round(($v['fzjjianyanf'] + $v['fnoxpaifangf']
	 							+ $v['flvtuf'] + $v['fjizuojijiaf']	+ $v['fzhusuf'] +   $v['fguoyejintie']
	 							+ $v['franyouf']+  $v['fguoluf']  +  $v['fzhengshuf']) ,2)   ;
	 				}
	 				//船检费BV   25004
	 				if(in_array($FRepKey,['25004'])){
	 					if($v['fchuanjishe'] !== 'BV'){
	 						showMsg(400,'船社级不一致，请检查(是否是大写)');
	 					}
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername;
	 					$resMX[$k]['fchanjianfeibv']  = round(($v['fzjjianyanf'] + $v['fnoxpaifangf']
	 							+ $v['flvtuf'] + $v['fjizuojijiaf']	+ $v['fzhusuf'] +  $v['franyouf']
	 							+  $v['fguoluf']  +  $v['fzhengshuf']) ,2)   ;
	 				}
	 				//船检费DNV   25005
	 				if(in_array($FRepKey,['25005'])){
	 					if($v['fchuanjishe'] !== 'DNV'){
	 						showMsg(400,'船社级不一致，请检查(是否是大写)');
	 					}
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername ;
	 					$resMX[$k]['fchanjianfeidnv']  = round(($v['fzjjianyanf'] + $v['fnoxpaifangf']
	 							+ $v['flvtuf'] + $v['fjizuojijiaf']	+ $v['fzhusuf'] +   $v['franyouf']
	 							+  $v['fguoluf']  +  $v['fchuchaibutie'] +  $v['fzhengshuf']) ,2)   ;
	 				}
	 				
	 				//运保费  26016
	 				if(in_array($FRepKey,['26016'  ])){
	 					$resMX[$k]['fbaoxianfei'] = $v['fsaleamount'] * $v['ffeilv'] ;
	 					$resMX[$k]['fyunshufei'] =  $v['fhailishu'] *  $v['fhailiprice']  ;
	 					$resMX[$k]['fallamount'] =  round($resMX[$k]['fbaoxianfei'] *(1+$cs['fsetffax']/100) / $cs['fsettuzhiss'] ,2)
	 					+  round(($resMX[$k]['fyunshufei']+  $v['fysguding'])*(1+$cs['fsetffax']/100) / $cs['fsetyunbaof'] ,2)    ;
// 	 					dd(111 ,$resMX);
	 				}
	 				//水电费  26011
	 				if(in_array($FRepKey,['26011'  ])){
	 					//
	 					$temjs26011 = farraySearch($v['fmodel'],$TempDataJS);
	 					if(!$temjs26011){
	 						showMsg(400,'技术中心不存在这个机型，请检查');
	 					}
	 					$v['fjgcjdw'] = $temjs26011['fzzjweight'];
	 					$v['fjgcjdwprice'] = empty($cs['fsetshuidianjgcjprice'])?0:$cs['fsetshuidianjgcjprice'];
	 					$v['fjgcjdwamount'] =  ($v['fjgcjdw']??0) * ($v['fjgcjdwprice']??0)  ;
	 					
	 					$resMX[$k]['fjgcjdw'] = $temjs26011['fzzjweight'] ;
	 					$resMX[$k]['fjgcjdwprice'] = $v['fjgcjdwprice'] ;
	 					$resMX[$k]['fjgcjdwamount'] =  ($v['fjgcjdw']??0) * ($v['fjgcjdwprice']??0)  ;
	 					$resMX[$k]['fallamount'] =  ($resMX[$k]['fjgcjdwamount']??0) + ($v['fjijiacj']??0 ) + ($v['fzhuangshicj']??0 )  + ($v['fhanjiecj']??0 ) ;
	 				}
	 				//辅材成本   机加工-28006   ，装试-28007, 结构-26008
	 				if(in_array($FRepKey,['26008'  ])){
	 					$temjs26008 = farraySearch($v['fmodel'],$TempDataJS);
	 					if(!$temjs26008){
	 						showMsg(400,'技术中心不存在这个机型，请检查');
	 					}
	 					$resMX[$k]['fzzjweight'] = $temjs26008['fzzjweight'] ;
	 					$resMX[$k]['fdunweiprice'] = $cs['fsetfucaidwprice'];
	 					$resMX[$k]['fdunweicb']  =  ($resMX[$k]['fzzjweight']??0) *  $resMX[$k]['fdunweiprice'] ;
	 					$resMX[$k]['fallamount'] =  ($v['fzjyouqi']??0) + ($v['ftuihuocb']??0 ) + ($v['fqitaftcb']??0 ) + $resMX[$k]['fdunweicb']??0  ;
	 				}
	 				if($FRepKey == 28006){
	 					//合计    不需要分摊
	 					$temjs28006 = farraySearch($v['fmodel'],$ProdData);
	 					if(!$temjs28006){
	 						showMsg(400,'技术中心不存在这个机型，请检查');
	 					}
	 					$resMX[$k]['fdaojufy'] =  $temjs28006['fdaojufy'] ;
	 					$resMX[$k]['fallamount']  =  ($resMX[$k]['fdaojufy']*$cs['fsetprodfy']??0) + ($v['ffentanfy']??0)  ;
	 				}
	 				if($FRepKey == 28007){
	 					$temjs280047 = farraySearch($v['fmodel'],$TempDataJS);
	 					if(!$temjs280047){
	 						showMsg(400,'技术中心不存在这个机型，请检查');
	 					}
	 					
	 					if($temjs280047){
	 						if($temjs280047['ffuliaopakeage'] == '535'){
	 							$resMX[$k]['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai535value'] ;
	 							$resMX[$k]['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw535value'] ;
	 						}
	 						if($temjs280047['ffuliaopakeage'] == '550'){
	 							$resMX[$k]['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai550value'];
	 							$resMX[$k]['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw550value'] ;
	 						}
	 					}else{
	 						showMsg(400,'辅材数据对应机型不正确');
	 					}
	 					// 装试车间低耗和包装物系数是根据550或者535计算的
	 					$resMX[$k]['fallamount'] =  ($resMX[$k]['fdihao']??0) + ($resMX[$k]['fbaozhuangwu']??0 ) + ($v['fyoulvqi']??0 )
	 					+ ($v['fqitayoupin']??0) + ($v['ffentanfycj']??0 ) + ($v['ffentanfysczl']??0)  ;
	 					
	 				}
	 				//售后维护成本
	 				if($FRepKey == 26012){
	 					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额  fshguding
	 					//售后调试成本
	 					$resMX[$k]['fallamount'] =  ($v['fshcailiao']??0) + ($v['fshrengong']??0 ) + ($v['fshchailv']??0 )+($v['fshguding']??0)  ;
	 				}
	 				//质量成本
	 				if($FRepKey == 26013){
	 					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fzlguding
	 					//售后调试成本
	 					$resMX[$k]['fallamount'] =  ($v['fcaigouamount']??0) + ($v['fjishuamount']??0 )+ ($v['fzlguding']??0 )    ;
	 				}
	 				
	 				//已录入机型
	 				if($FRepKey == 14008){
	 					$temjs14008 = farraySearch($v['fmodel'],$TempDataJS);
	 					if(!$temjs14008){
	 						showMsg(400,'技术中心不存在这个机型，请检查');
	 					}
	 					$v['fbrand'] = $temjs14008['fbrand']  ;
	 					$v['fpower']= $temjs14008['fpower']  ;
	 					$v['fmoli']= $temjs14008['fmoli']  ;
	 					$v['fzhuansu'] = $temjs14008['fzhuansu']  ;
	 					$v['funit']= $temjs14008['funit']  ;
	 					
	 					$resMX[$k]['fbrand'] =  $temjs14008['fbrand']  ;
	 					$resMX[$k]['fpower'] =  $temjs14008['fpower']  ;
	 					$resMX[$k]['fmoli'] =  $temjs14008['fmoli']  ;
	 					$resMX[$k]['fzhuansu'] =  $temjs14008['fzhuansu']  ;
	 					$resMX[$k]['funit'] =  $temjs14008['funit']  ;
	 				}
	 			}
	 		}
	 		$ArrUpload =[];
	 		$ICERData =[];
	 		 
 			$sql = "select * from {$db} where fmodel in ({$fmodelStr}) " ;
 			$ICERData = SqlServerUtil::execToSql($this->SqlServer,$sql);
 			$tmp = [];
 			if($ICERData){
 				$tmp = arraykeyToLowerTo($ICERData);
 				if($isCheck == 0 ){
 				    if(in_array(1,array_unique(array_column($tmp, 'fstatus')))){
 				        showMsg(400,'当前机型已审核，无法导入,需反审，请检查',1);
 				    }
 				}
 			}
 			
 			$ArrUpload = $tmp ;
//  			dd($ArrUpload);
	 		$cgData =[];
	 		$arr =[];
	 		if($ArrUpload){
// 	 			dd($insertRecords , $ArrUpload);
	 			// "_X_ROW_KEY" => "row_198" 
	 			//  存在
	 			foreach ($insertRecords as $ls =>&$lsVal){
	 				unset($lsVal['_x_row_key']) ;
// 	 				unset($lsVal['fstatus']) ;
	 				$lsVal['fstatus'] = 0 ; 
	 				$lsVal['fcreatetime'] = getCurrentTime();
	 				if(in_array($FRepKey,['14008' ,'14010','26016' ,'26013','26012','26011','28006','28007','26008' ])){
	 					$lsVal['fbrand'] =  strtoupper(str_replace(' ','',$lsVal['fbrand'] )) ;
	 				}
	 				//生产部
	 				if(in_array($FRepKey,['14010'  ])){
	 					$lsVal['fweiwaiamount'] =  round($lsVal['fjuanyuan']+$lsVal['flingxingjg']+$lsVal['fsuanxilh']+$lsVal['fjizuo']
	 							+$lsVal['fjijia']+$lsVal['fqita']+$lsVal['fpaiyanguanzq']+$lsVal['fzoutai']
	 							+$lsVal['fgongzhuangjt']+$lsVal['fbgrpaiyanguan']+$lsVal['fbgrjinqi']+$lsVal['fbgrzhengji'] ,2);
	 					$lsVal['ffygzzjamount']= round($lsVal['fjijiagz']+$lsVal['fzhuangshigz']+$lsVal['fhanjiegz']+$lsVal['fshichegz']+$lsVal['ffayungzzj'] ,2);
	 					$lsVal['ffygzfdamount']= round($lsVal['fjijiagz']+$lsVal['fzhuangshigz']+$lsVal['fhanjiegz']+$lsVal['fshichegz']+$lsVal['ffayungzfd'] ,2);
	 					
	 				}
	 				 				
	 				//运保费// 26016
	 				////  1.保险费： 用销售金额乘以费率 *（1+增值税率） / 1.06
	 				//    2.运输费。运输地点，海里数，单位海里价格  * 1.13 /1.09
	 				if(in_array($FRepKey,['26016'  ])){
	 					$lsVal['fbaoxianfei'] = $lsVal['fsaleamount'] * $lsVal['ffeilv'] ;
	 					$lsVal['fyunshufei'] =  $lsVal['fhailishu'] *  $lsVal['fhailiprice']  ;
	 					$lsVal['fallamount'] =  round($lsVal['fbaoxianfei'] *(1+$cs['fsetffax']/100) / $cs['fsettuzhiss'] ,2)
	 					+  round(($lsVal['fyunshufei']+  $lsVal['fysguding'])*(1+$cs['fsetffax']/100) / $cs['fsetyunbaof'] ,2)    ;
	 						
	 				}
	 				//水电费
	 				if(in_array($FRepKey,['26011'  ])){
	 					$lsVal['fjgcjdwamount'] =  ($lsVal['fjgcjdw']??0) * ($lsVal['fjgcjdwprice']??0)  ;
	 					$lsVal['fallamount'] =  ($lsVal['fjgcjdwamount']??0) + ($lsVal['fjijiacj']??0 ) + ($lsVal['fzhuangshicj']??0 )  + ($lsVal['fhanjiecj']??0 ) ;
	 				}
	 				// 辅材成本 26008
	 				if(in_array($FRepKey,['26008'  ])){
	 					$temjs26008 = farraySearch($lsVal['fmodel'],$TempDataJS);
	 					$lsVal['fzzjweight'] = $temjs26008['fzzjweight'] ;
	 					$lsVal['fdunweiprice'] = $cs['fsetfucaidwprice'];
	 					$lsVal['fdunweicb']  =  ($lsVal['fzzjweight']??0) *  $lsVal['fdunweiprice'] ;
	 					$lsVal['fallamount'] =  ($lsVal['fzjyouqi']??0) + ($lsVal['ftuihuocb']??0 ) + ($lsVal['fqitaftcb']??0 ) + $lsVal['fdunweicb']??0  ;
	 				}
	 				//辅材成本 28006  -- 机加工
	 				if($FRepKey == 28006){
	 					//合计    不需要分摊
	 					$temjs28006 = farraySearch($lsVal['fmodel'],$ProdData);
	 					$lsVal['fdaojufy'] =  $temjs28006['fdaojufy'] ; 
	 					$lsVal['fallamount']  =  ($lsVal['fdaojufy']*$cs['fsetprodfy']??0) + ($lsVal['ffentanfy']??0)  ;
	 				}
	 				
	 				//辅材成本 28007  -- 装试
	 				if($FRepKey == 28007){
	 					$temjs280047 = farraySearch($lsVal['fmodel'],$TempDataJS);
	 					if($temjs280047){
	 						if($temjs280047['ffuliaopakeage'] == '535'){
	 							$lsVal['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai535value'] ;
	 							$lsVal['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw535value'] ;
	 						}
	 						if($temjs280047['ffuliaopakeage'] == '550'){
	 							$lsVal['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai550value'];
	 							$lsVal['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw550value'] ;
	 						}
	 					}else{
	 						showMsg(400,'辅材数据对应机型不正确');
	 					}
	 					// 装试车间低耗和包装物系数是根据550或者535计算的
	 					$lsVal['fallamount'] =  ($lsVal['fdihao']??0) + ($lsVal['fbaozhuangwu']??0 ) + ($lsVal['fyoulvqi']??0 )
	 					+ ($lsVal['fqitayoupin']??0) + ($lsVal['ffentanfycj']??0 ) + ($lsVal['ffentanfysczl']??0)  ;
	 					
	 				}
	 				
	 				//售后调试成本  26012
	 				if($FRepKey == 26012){
	 					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额  fshguding
	 					//售后调试成本
	 					$lsVal['fallamount'] =  ($lsVal['fshcailiao']??0) + ($lsVal['fshrengong']??0 ) + ($lsVal['fshchailv']??0 )+($lsVal['fshguding']??0)  ;
	 				}
	 				
	 				// 质量成本  26013
	 				if($FRepKey == 26013){
	 					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fzlguding
	 					//售后调试成本
	 					$lsVal['fallamount'] =  ($lsVal['fcaigouamount']??0) + ($lsVal['fjishuamount']??0 )+ ($lsVal['fzlguding']??0 )    ;
	 				}
	 				//船检费
	 				if(in_array($FRepKey,['26002'])){
	 					$lsVal['fchanjianfeiccs']  = round(($lsVal['fzjjianyanf'] + $lsVal['fnoxpaifangf'] 
	 							+ $lsVal['flvtuf'] + $lsVal['fjizuojijiaf']	+ $lsVal['fzhusuf'] +   $lsVal['fjiaotongf'] 
	 							+  $lsVal['ftongxunf']  +  $lsVal['fzhengshuf'])/$cs['fsetchuanjianccs'],2)   ;
	 				}
	 				
	 				if(in_array($FRepKey,['25002'])){
	 					
	 					$vup['fexchangerate'] = $fexchangerate;
	 					//整机检验费人民币
	 					$lsVal['fzjjianyanfrmb'] =  round( $lsVal['fzjjianyanf']*$fexchangerate ,2);
	 					//NOX排放费人民币
	 					$lsVal['fnoxpaifangfrmb'] = round($lsVal['fnoxpaifangf'] *$fexchangerate,2) ;
	 					//证书费人民币
	 					$lsVal['fzhengshufrmb'] =  round($lsVal['fzhengshuf'] *$fexchangerate ,2);
	 					//旅途时间费用人民币
	 					$lsVal['flvtufrmb'] =  round( $lsVal['flvtuf'] *$fexchangerate*30 ,2) ;
	 					
	 					$lsVal['fchanjianfeiabs']  = round(($lsVal['fzjjianyanfrmb'] + $lsVal['fnoxpaifangfrmb']
	 							+ $lsVal['fzhengshufrmb'] + $lsVal['flvtufrmb']	+ $lsVal['fzhusufrmb'] +   $lsVal['franyoufrmb']
	 							+  $lsVal['fguolufrmb'] +  $lsVal['fhuosibutiermb']   ) ,2)   ;
	 					
	 				}
	 				if(in_array($FRepKey,['25003'])){
	 					$lsVal['fchanjianfeilr']  = round(($lsVal['fzjjianyanf'] + $lsVal['fnoxpaifangf']
	 							+ $lsVal['flvtuf'] + $lsVal['fjizuojijiaf']	+ $lsVal['fzhusuf'] +   $lsVal['fguoyejintie']
	 							+ $lsVal['franyouf']+  $lsVal['fguoluf']  +  $lsVal['fzhengshuf']) ,2)   ;
	 				}
	 				
	 				if(in_array($FRepKey,['25004'])){
	 					$lsVal['fchanjianfeibv']  = round(($lsVal['fzjjianyanf'] + $lsVal['fnoxpaifangf']
	 							+ $lsVal['flvtuf'] + $lsVal['fjizuojijiaf']	+ $lsVal['fzhusuf'] +  $lsVal['franyouf']
	 							+  $lsVal['fguoluf']  +  $lsVal['fzhengshuf']) ,2)   ;
	 				}
	 				
	 				if(in_array($FRepKey,['25005'])){
	 					$lsVal['fchanjianfeidnv']  = round(($lsVal['fzjjianyanf'] + $lsVal['fnoxpaifangf']
	 							+ $lsVal['flvtuf'] + $lsVal['fjizuojijiaf']	+ $lsVal['fzhusuf'] +   $lsVal['franyouf']
	 							+  $lsVal['fguoluf']  +  $lsVal['fchuchaibutie'] +  $lsVal['fzhengshuf']) ,2)   ;
	 				}
	 				
	 				
	 				foreach ($ArrUpload as $itemkey=>$itemVal){
	 					if($lsVal['fmodel'] == $itemVal['fmodel']  )
	 					{
	 						//存在
	 						$arr[$ls] = $lsVal;
	 						$arr[$ls]['fid'] = $itemVal['fid'];
	 						$arr[$ls]['fcreatetime'] = getCurrentTime();
	 						if(in_array($FRepKey,['25002'])){
	 							$arr[$ls]['fexchangerate'] = $fexchangerate;
	 							
	 						}
	 						unset($insertRecords[$ls]);
	 					}
	 				}
	 			}
	 			$insert1=true;
	 			$update=true;
	 			if($insertRecords && count($insertRecords)>0){
	 				$insert1=SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db, $insertRecords);
	 				$this->writeLog(getMkName($FRepKey),'导入新增' , $FRepKey , $insertRecords ,$opername);
	 				
	 			}
	 			if($arr && count($arr)>0){
	 				//dd($arr);
	 				$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer, $db, $arr);
	 				$this->writeLog(getMkName($FRepKey),'导入修改' , $FRepKey , $arr ,$opername);
	 			}
	 			
	 		}else{
	 			//无全部导入
	 			foreach ($insertRecords as $kup=>&$vup)
	 			{
	 				$vup['fcreatetime'] = getCurrentTime();
	 				if(in_array($FRepKey,[ '14008' ,'14010','26016' ,'26013','26012','26011','28006','28007','26008' ])){
	 					$vup['fbrand'] = strtoupper(str_replace(' ','',$vup['fbrand'] )) ;
	 				}
	 				// _x_row_key
	 				unset($vup['_x_row_key']);
	 				//生产部
	 				if(in_array($FRepKey,['14010'  ])){
	 					$vup['fweiwaiamount'] =  round($vup['fjuanyuan']+$vup['flingxingjg']+$vup['fsuanxilh']+$vup['fjizuo']
	 							+$vup['fjijia']+$vup['fqita']+$vup['fpaiyanguanzq']+$vup['fzoutai']
	 							+$vup['fgongzhuangjt']+$vup['fbgrpaiyanguan']+$vup['fbgrjinqi']+$vup['fbgrzhengji'] ,2);
	 					
	 					$vup['ffygzzjamount']= round($vup['fjijiagz']+$vup['fzhuangshigz']+$vup['fhanjiegz']+$vup['fshichegz']+$vup['ffayungzzj'] ,2);
	 					$vup['ffygzfdamount']= round($vup['fjijiagz']+$vup['fzhuangshigz']+$vup['fhanjiegz']+$vup['fshichegz']+$vup['ffayungzfd'] ,2);
	 					
	 				}
	 				
	 				//运保费// 26016
	 				if(in_array($FRepKey,['26016'  ])){
	 					$vup['fbaoxianfei'] = $vup['fsaleamount'] * $vup['ffeilv'] ;
	 					$vup['fyunshufei'] =  $vup['fhailishu'] *  $vup['fhailiprice']  ;
	 					$vup['fallamount'] =  round($vup['fbaoxianfei'] *(1+$cs['fsetffax']/100) / $cs['fsettuzhiss'] ,2)
	 					+  round(($vup['fyunshufei']+  $vup['fysguding'])*(1+$cs['fsetffax']/100) / $cs['fsetyunbaof'],2)    ;
	 				}
	 				//水电费
	 				if(in_array($FRepKey,['26011'  ])){
	 					$vup['fjgcjdwamount'] =  ($vup['fjgcjdw']??0) * ($vup['fjgcjdwprice']??0)  ;
	 					$vup['fallamount'] =  ($vup['fjgcjdwamount']??0) + ($vup['fjijiacj']??0 ) + ($vup['fzhuangshicj']??0 )  + ($vup['fhanjiecj']??0 ) ;
	 				}
	 				// 辅材成本 26008 
	 				if(in_array($FRepKey,['26008'  ])){
	 					$temjs26008 = farraySearch($vup['fmodel'],$TempDataJS);
	 					$vup['fzzjweight'] = $temjs26008['fzzjweight'] ;
	 					$vup['fdunweiprice'] = $cs['fsetfucaidwprice'];
	 					$vup['fdunweicb']  =  ($vup['fzzjweight']??0) *  $vup['fdunweiprice'] ;
	 					$vup['fallamount'] =  ($vup['fzjyouqi']??0) + ($vup['ftuihuocb']??0 ) + ($vup['fqitaftcb']??0 ) + $vup['fdunweicb']??0  ;
	 					 
	 				}
	 				//辅材成本 28006  -- 机加工
	 				if($FRepKey == 28006){
	 					//合计    不需要分摊
	 					$temjs28006 = farraySearch($vup['fmodel'],$ProdData);
	 					$vup['fdaojufy']  =  $temjs28006['fdaojufy'] ;
	 					$vup['fallamount']  =  ($vup['fdaojufy']*$cs['fsetprodfy']??0) + ($vup['ffentanfy']??0)  ;
	 				}
	 				
	 				//辅材成本 28007  -- 装试
	 				if($FRepKey == 28007){
	 					$temjs280047 = farraySearch($vup['fmodel'],$TempDataJS);
	 					if($temjs280047){
	 						if($temjs280047['ffuliaopakeage'] == '535'){
	 							$vup['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai535value'] ;
	 							$vup['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw535value'] ;
	 						}
	 						if($temjs280047['ffuliaopakeage'] == '550'){
	 							$vup['fdihao'] = $temjs280047['fdihao']* $cs['fsetfucai550value'];
	 							$vup['fbaozhuangwu'] = $temjs280047['fbaozhuangwu']* $cs['fsetfucaibzw550value'] ;
	 						}
	 					}else{
	 						showMsg(400,'辅材数据对应机型不正确');
	 					}
	 					// 装试车间低耗和包装物系数是根据550或者535计算的
	 					$vup['fallamount'] =  ($vup['fdihao']??0) + ($vup['fbaozhuangwu']??0 ) + ($vup['fyoulvqi']??0 )
	 					+ ($vup['fqitayoupin']??0) + ($vup['ffentanfycj']??0 ) + ($vup['ffentanfysczl']??0)  ;
	 				}
	 				
	 				//售后调试成本  26012
	 				if($FRepKey == 26012){
	 					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额  fshguding
	 					//售后调试成本
	 					$vup['fallamount'] =  ($vup['fshcailiao']??0) + ($vup['fshrengong']??0 ) + ($vup['fshchailv']??0 )+($vup['fshguding']??0)  ;
	 				}
	 				// 质量成本  26013
	 				if($FRepKey == 26013){
	 					// 1.按照售后差旅+人工+材料；   ，，	一种是固定金额 fzlguding
	 					//售后调试成本     fzlguding
	 					$vup['fallamount'] =  ($vup['fcaigouamount']??0) + ($vup['fjishuamount']??0 ) + ($vup['fzlguding']??0 )    ;
	 				}
	 					 				
	 			    if(in_array($FRepKey,['26002'])){
	 					$vup['fchanjianfeiccs']  = round(($vup['fzjjianyanf'] + $vup['fnoxpaifangf']
	 							+ $vup['flvtuf'] + $vup['fjizuojijiaf']	+ $vup['fzhusuf'] +   $vup['fjiaotongf']
	 							+  $vup['ftongxunf']  +  $vup['fzhengshuf'])/$cs['fsetchuanjianccs'],2)   ;
	 				}
	 				
	 				if(in_array($FRepKey,['25002'])){
	 					$vup['fexchangerate'] = $fexchangerate;
	 					//整机检验费人民币
	 					$vup['fzjjianyanfrmb'] =  round( $vup['fzjjianyanf']*$fexchangerate ,2);
	 					//NOX排放费人民币
	 					$vup['fnoxpaifangfrmb'] = round($vup['fnoxpaifangf'] *$fexchangerate,2) ;
	 					//证书费人民币
	 					$vup['fzhengshufrmb'] =  round($vup['fzhengshuf'] *$fexchangerate ,2);
	 					//旅途时间费用人民币
	 					$vup['flvtufrmb'] =  round( $vup['flvtuf'] *$fexchangerate*30 ,2) ;
	 					
	 					$vup['fchanjianfeiabs']  = round(($vup['fzjjianyanfrmb'] + $vup['fnoxpaifangfrmb']
	 							+ $vup['fzhengshufrmb'] + $vup['flvtufrmb']	+ $vup['fzhusufrmb'] +   $vup['franyoufrmb']
	 							+  $vup['fguolufrmb'] +  $vup['fhuosibutiermb']   ) ,2)   ;
	 				
	 				}
	 				if(in_array($FRepKey,['25003'])){
	 					$vup['fchanjianfeilr']  = round(($vup['fzjjianyanf'] + $vup['fnoxpaifangf']
	 							+ $vup['flvtuf'] + $vup['fjizuojijiaf']	+ $vup['fzhusuf'] +   $vup['fguoyejintie']
	 							+ $vup['franyouf']+  $vup['fguoluf']  +  $vup['fzhengshuf']) ,2)   ;
	 				}
	 				
	 				if(in_array($FRepKey,['25004'])){
	 					$vup['fchanjianfeibv']  = round(($vup['fzjjianyanf'] + $vup['fnoxpaifangf']
	 							+ $vup['flvtuf'] + $vup['fjizuojijiaf']	+ $vup['fzhusuf'] +  $vup['franyouf']
	 							+  $vup['fguoluf']  +  $vup['fzhengshuf']) ,2)   ;
	 				}
	 				
	 				if(in_array($FRepKey,['25005'])){
	 					$vup['fchanjianfeidnv']  = round(($vup['fzjjianyanf'] + $vup['fnoxpaifangf']
	 							+ $vup['flvtuf'] + $vup['fjizuojijiaf']	+ $vup['fzhusuf'] +   $vup['franyouf']
	 							+  $vup['fguoluf']  +  $vup['fchuchaibutie'] +  $vup['fzhengshuf']) ,2)   ;
	 				}
	 				
	 			}
// 	 		dd($insertRecords);
	 			$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insertRecords);
	 			$this->writeLog(getMkName($FRepKey),'导入新增' , $FRepKey , $insertRecords ,$opername);
	 			
	 		}
	 		if(($insert1 && $update) || $insert2  ){
	 			//生产部 ，船检费-- 发短信 
	 			if(in_array($FRepKey,['14010','26002','25002','25003','25004','25005'  ]) ){
	 				//生产部列表 14010
 					$cs = $this->getSystemProfile(['FSetSendSMS'   ]);
 					$this->genSendSms($cs['fsetsendsms'],getMkName($FRepKey).' ，已导入,操作人：'.$opername);
	 				SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
	 			}
	 			// 
	 			if(in_array($FRepKey,['14008','26016', '26011','26008','28006','28007','26012','26013'  ]) ){
	 				SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
	 			}
	 			sqlsrv_commit($this->SqlServer);
	 			
	 			//只针对 生产机型 导入  -- 机加工 同步修改
	 			if(in_array($FRepKey,['14010'])){
	 				// 辅材成本 28006  -- 机加工  gz_Yfucaicbfjijia
	 				$sqljj = " select  v1.*,u1.fdaojuxiaohao as dj  from gz_Yfucaicbfjijia v1
	 				LEFT JOIN gz_YBaseProduce u1 on v1.fmodel = u1.fmodel
	 				where v1.fmodel in ({$fmodelStr}) and u1.fdaojuxiaohao <> v1.fdaojufy " ;
	 				$TempjjData = SqlServerUtil::execToSql($this->SqlServer,$sqljj );
	 				//机加工
	 				if(!empty($TempjjData)){
	 					$JJData =[];
	 					$TempjjDataT = arraykeyToLowerTo($TempjjData);
	 					if($TempjjDataT){
	 						foreach ($TempjjDataT as $k =>$v)
	 						{
	 							$JJData[$k]['fid'] = $v['fid'];
	 							$JJData[$k]['fdaojufy'] = $v['dj'];
	 							//合计    不需要分摊
	 							$JJData[$k]['fallamount'] = ($JJData[$k]['fdaojufy']*$cs['fsetprodfy']??0) + ($v['ffentanfy']??0)  ;
	 						}
	 						$insjj = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbfjijia',$JJData,'fid');
	 					}
	 				}
	 			}
	 			
	 			showMsg(0,'成功');
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}else{
	 		showMsg(1,'数据信息为空,请重新上传');
	 	}
	 	
	 }
	 
	 /**
	  * 技术中心 上传
	  * @date: 2023年3月6日 上午11:24:32
	  * @author: juyi
	  */
	 function FImportGENJS(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	
	 	$insertRecords = $data['data'];
	 	$fbrand = '';
	 	if($FRepKey == '26009'){
	 		$fbrand = 'WINGD';
	 	}elseif($FRepKey == '26022'){
	 		$fbrand = 'MAN';
	 	}
	 	
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$insertRecords = arraykeyToLowerTo($insertRecords);
	 	$db =columnBiao($FRepKey);//数据库
	 	// 	 	dd($data );
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$tmpModel = array_column($insertRecords, 'fmodel');
	 		$Modelone = array_unique($tmpModel)  ;
	 		// 	 		dd($one ,array_column($insertRecords, 'fmodel') );
	 		if(count($Modelone) != count($tmpModel) ){
	 			showMsg(400, 'Excel 机型有多个,或重复机型，支持唯一机型导入');
	 		}
	 		$insert1=false;
	 		$update=false;
	 		$insert2 =false;
	 		$fmodelStr =join("','", $tmpModel );
	 		$fmodelStr = "'".$fmodelStr ."'";
	 		$resMX =[];
	 		//获取字段
	 		$getVexTableColumnData = $this->getVexTableColumn($FRepKey ) ;
	 		foreach ($insertRecords as $k =>&$v)
	 		{
	 			foreach ($getVexTableColumnData as $kc=>$vc)
	 			{
	 				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='0' ) && $vc['freptype'] == 131 ){
	 					$v[$vc['frepfld']] =0;
	 				}
	 				
	 				if( !empty($v[$vc['frepfld']]) && $v[$vc['frepfld']]>0  && $vc['freptype'] == 131 ){
	 					$v[$vc['frepfld']] =round($v[$vc['frepfld']],$vc['fdecplaces']);
	 				}
	 				
	 				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
	 					$v[$vc['frepfld']] = '';
	 				}
	 				$v['fbrand'] = strtoupper(str_replace(' ','',$v['fbrand'] )); //品牌空格处理
	 				if($FRepKey == '14007'){
	 					$resMX[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
	 					$resMX[$k]['opertype'] = '导入' ;
	 					$resMX[$k]['opername'] = $opername;
	 					$resMX[$k]['fhejigs']= ($v['fhanjiegs']+$v['fjijiags']+$v['fzhuangshigs']);
	 					$resMX[$k]['fbrand'] = str_replace(' ','',$v['fbrand'] );
	 				}
	 			}
	 			unset($v['fcreatetime']);
	 			unset($v['_x_row_key']);
	 			//  辅料包装物基数 	550  ,535
	 			if(!in_array($v['ffuliaopakeage'],[550  ,535])){
	 				showMsg(400,$v['fmodel'].' 机型 ，辅料包装物基数，请填写 550 或 535');
	 			}
	 			
	 		}
	 		
	 		$Cs = $this->getSystemProfile(['FSetShuiDianjgcjPrice' ,'FSetFuCaiDWPrice','FSetFFAX', 'FSetFuCai550Value' ,'FSetFuCai535Value','FSetFuCaiBZW535Value','FSetFuCaiBZW550Value' ]);
	 		// 535
	 		$fucaibzwvalue535 = empty($Cs['fsetfucaibzw535value'])?0:$Cs['fsetfucaibzw535value'] ;
	 		$fucaivalue535 = empty($Cs['fsetfucai535value'])?0:$Cs['fsetfucai535value'] ;
	 		// 550
	 		$fucaibzwvalue550 = empty($Cs['fsetfucaibzw550value'])?0: $Cs['fsetfucaibzw550value'] ;
	 		$fucaivalue550 = empty($Cs['fsetfucai550value'])?0: $Cs['fsetfucai550value'] ;
	 		
// 	 		dd($insertRecords);
	 		$sql = "select  *  from gz_YBaseJS where fmodel in ({$fmodelStr}) " ;
	 		$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		$TempDataJS = [];
	 		
	 		if($TempData){
	 			$arr =[];
	 			$TempDataJS = arraykeyToLowerTo($TempData);
	 			foreach ($insertRecords as $ls =>&$lsVal){
	 				$lsVal['fhejigs']= ($lsVal['fhanjiegs']+$lsVal['fjijiags']+$lsVal['fzhuangshigs']);
	 				 
	 				foreach ($TempDataJS as $itemkey=>$itemVal){
	 					if($lsVal['fmodel'] == $itemVal['fmodel'] )
	 					{
	 						//存在
	 						$arr[$ls] = $lsVal;
	 						$arr[$ls]['fid'] = $itemVal['fid'];
	 						$arr[$ls]['fcreatetime'] = getCurrentTime();
	 						unset($insertRecords[$ls]);
	 					}
	 				}
	 			}
	 			// dd( $arr , $insertRecords);
	 			$insert1=true;
	 			$update=true;
	 			
	 			$inssdf = true;
	 			$inshj = true;
	 			$insjj = true;
	 			$inszs = true;
	 			
	 			if($insertRecords && count($insertRecords)>0){
	 				$insert1=SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db, $insertRecords); 
	 				
	 				$this->writeLog(getMkName($FRepKey),'导入新增' , $FRepKey , $insertRecords ,$opername);
	 			}
	 			if($arr && count($arr)>0){
	 				$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer, $db, $arr);
	 				$this->writeLog(getMkName($FRepKey),'导入修改' , $FRepKey , $arr ,$opername);
	 			}
	 			
	 		}else{
	 			//直接插入
	 			//无全部导入
	 			foreach ($insertRecords as $kup=>&$vup)
	 			{
	 				$insertRecords[$kup]['fhejigs']= ($vup['fhanjiegs']+$vup['fjijiags']+$vup['fzhuangshigs']);
	 				
	 			}
	 			// dd($insertRecords);
	 			$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insertRecords);
	 			$this->writeLog(getMkName($FRepKey),'导入新增' , $FRepKey , $insertRecords ,$opername);
	 		}
	 		if(($insert1 && $update && $inssdf && $inshj && $insjj && $inszs) || $insert2  ){
	 			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
	 			sqlsrv_commit($this->SqlServer);
	 			
	 			// 水电费  26011    技术中心  ，，  自制件重量
	 			$sqlsdf = "select  v1.*,u1.fzzjweight as zzj  from gz_Yshuidianf v1
	 			LEFT JOIN gz_YBaseJS u1 on v1.fmodel = u1.fmodel where v1.fmodel in ({$fmodelStr})
	 			and u1.fzzjweight <> v1.fjgcjDW " ;
	 			$TempsdfData = SqlServerUtil::execToSql($this->SqlServer,$sqlsdf );
	 			// 辅材成本 26008 结构
	 			$sqlhj = "select  v1.*,u1.fzzjweight as zzj  from gz_Yfucaicbf v1
	 			LEFT JOIN gz_YBaseJS u1 on v1.fmodel = u1.fmodel
	 			where v1.fmodel in ({$fmodelStr})  and u1.fzzjweight <> v1.fzzjWeight " ;
	 			$TemphjData = SqlServerUtil::execToSql($this->SqlServer,$sqlhj );
	 			
	 			// 辅材成本 28007 -- 装试  gz_Yfucaicbfzshi
	 			$sqlzs = "select   u1.fpackage ,u1.ffuliao,u1.ffuliaopakeage,
	 			v1.fdihao as dh,v1.fbaozhuangwu as bzw,
	 			case when u1.ffuliaopakeage =535 then  {$fucaibzwvalue535}
	 			when  u1.ffuliaopakeage =550 then  {$fucaibzwvalue550}
	 			else 0 End as bzwxs,
	 			case when u1.ffuliaopakeage =535 then {$fucaivalue535}
	 			when  u1.ffuliaopakeage =550 then  {$fucaivalue550}
	 			else 0 End as dhxs,
	 			v1.*
	 			from gz_Yfucaicbfzshi v1
	 			LEFT JOIN gz_YBaseJS u1 on v1.fmodel = u1.fmodel
	 			where v1.fmodel in ({$fmodelStr})
	 			and ( u1.fpackage <> (case when u1.ffuliaopakeage =535 then v1.fbaozhuangwu/{$fucaibzwvalue535}
	 			when  u1.ffuliaopakeage =550 then v1.fbaozhuangwu/{$fucaibzwvalue550}
	 			else 0 End)  or u1.ffuliao <> (case when u1.ffuliaopakeage =535 then v1.fdihao/{$fucaivalue535}
	 			when  u1.ffuliaopakeage =550 then v1.fdihao/{$fucaivalue550}
	 			else 0 End) ) " ;
	 			$TempzsData = SqlServerUtil::execToSql($this->SqlServer,$sqlzs );
	 			//只对 水电费  26011 ，辅材 做更新操作
	 			if(!empty($TempsdfData)){
	 				// $TempDataJS -- 技术 自制件重量  
	 				$SDFData =[];
	 				$TempsdfDataT = arraykeyToLowerTo($TempsdfData);
	 				if($TempsdfDataT){
	 					foreach ($TempsdfDataT as $k =>$v)
	 					{
	 						$SDFData[$k]['fid'] = $v['fid'];
	 						$SDFData[$k]['fjgcjdwprice'] = $Cs['fsetshuidianjgcjprice'];//参数设置水电费价格
	 						$SDFData[$k]['fjgcjdw'] = $v['zzj'];
	 						$SDFData[$k]['fjgcjdwamount'] = $SDFData[$k]['fjgcjdw'] * $SDFData[$k]['fjgcjdwprice']  ;
	 						//水电费合计
	 						$SDFData[$k]['fallamount'] = $SDFData[$k]['fjgcjdwamount']+ ($v['fjijiacj']??0 ) + ($v['fzhuangshicj']??0 )  + ($v['fhanjiecj']??0 ) ;
	 						//水电费合计 含税
	 						$SDFData[$k]['ffaxallamount']  = (floatval($SDFData[$k]['fjgcjdwamount'])  + floatval($v['fjijiacj'])
	 								+ floatval($v['fzhuangshicj']) + ($v['fhanjiecj']??0 ))*(1+$Cs['fsetffax']/100)   ;
	 					}
	 					$inssdf = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yshuidianf',$SDFData,'fid');
	 				}
	 				
	 			}
	 			//焊接  -- 技术 自制件重量
	 			if(!empty($TemphjData)){
	 				// // 结构车间-制造费用表  用技术中心的自制件重量引过来
	 				// 按吨位计算的成本 fdunweicb  = 根据单价 乘以 吨位    这里 还差一个 吨位计算成本
	 				$HJData =[];
	 				$TemphjDataT = arraykeyToLowerTo($TemphjData);
	 				if($TemphjDataT){
	 					foreach ($TemphjDataT as $k =>$v)
	 					{
	 						$HJData[$k]['fid'] = $v['fid'];
	 						$HJData[$k]['fdunweiprice'] = empty($Cs['fsetfucaidwprice'])?0:$Cs['fsetfucaidwprice'];  //辅材成本 -- 单位吨位价格
	 						$HJData[$k]['fzzjweight'] = $v['zzj'];
	 						$HJData[$k]['fdunweicb']  =  ($HJData[$k]['fzzjweight']??0) *  $HJData[$k]['fdunweiprice'] ;
	 						$HJData[$k]['fallamount'] =  ($v['fzjyouqi']??0) + ($v['ftuihuocb']??0 ) + ($v['fqitaftcb']??0 ) + $HJData[$k]['fdunweicb']??0  ;
	 					}
	 					$inshj = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbf',$HJData,'fid');
	 				}
	 			}
	 			//装试 -- 技术低耗  ，包装物
	 			if(!empty($TempzsData)){
	 				$ZSData =[];
	 				$TempzsDataT = arraykeyToLowerTo($TempzsData);
	 				if($TempzsDataT){
	 					foreach ($TempzsDataT as $k =>$v)
	 					{
	 						$ZSData[$k]['fid'] = $v['fid'];
	 						// $Cs
	 						$ZSData[$k]['fdihao'] = $v['dhxs']* $v['ffuliao']  ;
	 						$ZSData[$k]['fbaozhuangwu'] = $v['bzwxs']* $v['fpackage']  ;
	 						$ZSData[$k]['fallamount'] =  ($ZSData[$k]['fdihao']??0) + ($ZSData[$k]['fbaozhuangwu']??0 ) + ($v['fyoulvqi']??0 ) + ($v['fqitayoupin']??0)  + ($v['ffentanfycj']??0 ) + ($v['ffentanfysczl']??0)  ;
	 					}
	 					$inszs = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbfzshi',$ZSData,'fid');
	 				}
	 			}
	 			
	 			showMsg(0,'成功');
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}else{
	 		showMsg(1,'数据信息为空,请重新上传');
	 	}
	 	
	 }
	 
	 
	 
	 /**
	  * 各部门 加账 数据 更新 ==   加账成本管理列表  （技术、采购、其他）
	  * @date: 2023年3月2日 下午6:55:39
	  * @author: juyi
	  * 加账成本管理 
	  */
	 function FImportJZDetail(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	
	 	$insertRecords = $data['data'];
	 	//26005 采购 
// 	 	if($FRepKey == '26005'){
// 	 		//判断采购是否已经确认
// 	 	}
// 	 	// 26023 技术
// 	 	if($FRepKey == '26023'){
// 	 		//
// 	 	}
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db =columnBiao($FRepKey);
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$fprodno= $insertRecords[0]['fprodno'];
	 		$one = array_unique(array_column($insertRecords, 'fprodno'))  ;
// 	 		dd($one);
	 		if(count($one) >1  ){
	 			showMsg(400, ' 机型只支持一个机型导入');
	 		}
	 		
	 		//采购 和 加账  
	 		foreach ($insertRecords as $k =>$v)
	 		{
	 			$fcodeStr = substr($v['fcode'],0,2);
	 			if($fcodeStr != 'JZ'){
	 				showMsg(400,'请导入加账代码不正确，请检查');
	 			}
	 		}
	 		
	 		
	 		$arrTT = array_column($insertRecords, 'fcode');
	 	
	 		//机型 JS 是否有 判断
	 		$sql = "select  fbrand ,fmodel,fpower  from gz_YBaseJS where fmodel ='{$fprodno}' " ;
	 		$TempDataJS = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if(empty($TempDataJS)){
	 			showMsg(400, '技术中心不存在这个机型:'.$fprodno.'，请确认');
	 		}
// 	 		dd($insertRecords);
	 		
	 		//fcode  是否存在 设置里
	 		$fcode =join("','", $arrTT);
	 		$fcodeStr = "'".$fcode ."'";
	 		$sql = "select fid, fcode from gz_YjiazhangcbfSet where 1=1 and fcode  in ({$fcodeStr})" ;
	 		$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if($SetCodeData){
	 			$arr2 = array_column($SetCodeData, 'fcode');
	 			$arrayDiff = array_diff($arrTT ,$arr2 ) ;
	 			if($arrayDiff){
	 				showMsg(400, join(',',$arrayDiff).' 导入代码不存在，请联系采购或技术');
	 			}
	 		}
	 		
	 		//判断当前机型是否已存在
	 		$tmpfcode = array_column($insertRecords, 'fcode');
	 		$Modelone = array_unique($tmpfcode)  ;
	 		if(count($Modelone) != count($tmpfcode) ){
	 			showMsg(400, 'Excel导入中 代码存在多个，支持唯一代码导入');
	 		}
	 		
// 	 		dd($insertRecords);
	 		// and fcode  in ({$fcodeStr})
	 		$sql = "select fid,fcode,fprodno,fstatus,fallamount from gz_YjiazhangcbfMX where fprodno='{$fprodno}' and fcode  in ({$fcodeStr})" ;
	 		// 	echo $sql ;die;
	 		$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if(in_array(1,array_unique(array_column($TempData, 'fstatus')))){
	 			showMsg(400,$fprodno.'当前已审核，无法导入');
	 		}
	 		$insert1=false;
	 		$update=false;
	 		$insert2 =false;
// 	 		dd(45555555);
	 		
	 		$cgData =[];
	 		$arr =[];
	 		$resMX =[];
	 		if($TempData){
// 	 			dd($insertRecords);
				/* fbrand" => "WINGD"
			    "fcode" => "JZW001"
			    "fname" => "HPSCR系统（低硫油）"
			    "fprodno" => "6X40-B"
			    "fallamount" => "25"
			    "_X_ROW_KEY" => "row_9" */
	 			//存在
	 			// 				dd($TempData);
	 			foreach ($insertRecords as $ls =>&$lsVal){
	 				unset($lsVal['_X_ROW_KEY']) ;
	 				unset($lsVal['fname']) ;
	 				
	 				$resMX[$ls]['fbrand'] = strtoupper(str_replace(' ','',$lsVal['fbrand']))  ; 
	 				$resMX[$ls]['fprodno'] = $lsVal['fprodno'] ; 
	 				$resMX[$ls]['fcode']=  $lsVal['fcode'] ;
	 				$resMX[$ls]['fallamount']=  $lsVal['fallamount'] ;
	 				
	 				foreach ($TempData as $itemkey=>$itemVal){
	 					if($lsVal['fprodno'] == $itemVal['fprodno'] && $lsVal['fcode'] == $itemVal['fcode'])
	 					{
	 						$arr[$ls]['fid'] =   $itemVal['fid'];
	 						//存在
	 						$arr[$ls]['fprodno'] =  $lsVal['fprodno'] ;
	 						$arr[$ls]['fcode']= $lsVal['fcode'] ;
	 						$arr[$ls]['fallamount']= $lsVal['fallamount'] ;
	 						$arr[$ls]['fbrand'] =  strtoupper(str_replace(' ','',$lsVal['fbrand'])); 
// 	 						$arr[$ls]['fbillno']= $lsVal['fbillno'] ;
	 						unset($insertRecords[$ls]);
	 					}
	 				}
	 			}
// 	 			dd( $arr , $insertRecords);
	 			$insert1=true;
	 			$update=true;
	 			if($insertRecords && count($insertRecords)>0){
	 				$insert1=SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db.'MX', $insertRecords);
	 			}
	 			if($arr && count($arr)>0){
	 				//dd($arr);
	 				$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer, $db.'MX', $arr);
	 			}
	 			
	 		}else{
	 			//无全部导入
	 			foreach ($insertRecords as $kup=>&$vup)
	 			{
	 				if(empty($vup['fcode']) || empty($vup['fprodno']) ){
	 					showMsg(400, ' 导入数据'.$vup['fname'].'机型或代码为空' );
	 				}
	 				$cgData[$kup]['fbrand'] =  strtoupper(str_replace(' ','',$vup['fbrand'])); 
	 				$cgData[$kup]['fprodno'] =  $vup['fprodno'] ;
	 				$cgData[$kup]['fcode']= $vup['fcode'] ;
	 				$cgData[$kup]['fallamount']= $vup['fallamount'] ;
// 	 				$cgData[$kup]['fbillno']= $vup['fbillno'] ;
	 				// $cgData[$kup]['fnote']= $vup['fremark'] ;
	 				
	 				$resMX[$kup]['fbrand'] = $vup['fbrand'] ; 
	 				$resMX[$kup]['fprodno'] =  $vup['fprodno'] ;
	 				$resMX[$kup]['fcode']= $vup['fcode'] ;
	 				$resMX[$kup]['fallamount']= $vup['fallamount'] ;
	 				
	 			}
	 			
	 			// 	$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fprodno'=>   "'".$fprodno."'"  ],true);
	 			$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $cgData);
// 	 			$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
// 	 			dd(2233);
	 		}
	 		if(($insert1 && $update) || $insert2  ){
	 			sqlsrv_commit($this->SqlServer);
	 			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX_JSCG' , $resMX);
	 			
	 			showMsg(0,'成功');
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}else{
	 		showMsg(1,'数据信息为空');
	 	}
	 	
	 }
	 
	 
	 /**
	 * 正式报价(加账)管理   流水号  加账 --业务 导入 --》 
	 * @date: 2023年3月10日 下午1:36:32
	 * @author: juyi
	 */
	 function FHXJZImportYW(Request $request){
		 $FRepKey = $request->get('FRepKey');
		 $opername= $request->get('opername');
		 $data =  $request->all() ;
		 $fmodel = $request->get('fmodel');
		 $fbrand = $request->get('fbrand') ;
		 $fbillno = $request->get('fbillno') ;
		 $rows = $request->get('rows') ;
		 $insertRecords = $data['data'];
		 if(empty($fmodel)  || empty($fbillno)){
		 	showMsg(400,'机型 参数错误');
		 }
		 if(empty($rows)){
		 	showMsg(400,'当前行未选中');
		 }
		 $sxqty = $rows['fqty'] ;
		 $sql = "select fbrand  from gz_Ybasejs where  fmodel='{$fmodel}'  " ;
		 $jsData = SqlServerUtil::execToSql($this->SqlServer,$sql,2);
		 if(empty($jsData)){
		 	showMsg(400, $fmodel.' 机型对应品牌不存在，请检验，');
		 }
		 $fbrand = strtoupper(str_replace(' ','', $jsData['fbrand']));	  
		 // 启动事务
		 if (sqlsrv_begin_transaction($this->SqlServer) === false) {
		 	die(print_r(sqlsrv_errors(), true));
		 }
		 $db = 'gz_Yjiazhangcbf_HXJZ';
		// $cs = $this->getSystemProfile(['fsetZhuangShiRGprice','FSetRGzhuangshiCJPrice' ,'FSetFFAX' ,'FSetChaiYouPrice' ,'FSetQiGangPrice' ,'FSetRanqiPrice' , ]);
		 
		 if(!empty($insertRecords)){
		 	//判断当前机型是否已存在
		 	$arr1 = array_column($insertRecords, 'fcode');
		 	$fcode =join("','", $arr1);
		 	$fcodeStr = "'".$fcode ."'";
		 	
		 	//判断导入代码是否在 加账设置里
		 	$sql = "select fid,fbrand,fcode,fqty,ffaxAmount from gz_YjiazhangcbfSet where  fcode  in ({$fcodeStr}) and fbrand ='{$fbrand}'" ;
		 	$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
		 	if(empty($TempData)){
		 		showMsg(400,'当前品牌'.$fbrand.'导入品牌对应代码是否正确');
		 	}
		 	if($TempData){
		 		$arr2 = array_column($TempData, 'fcode');
		 		$arrayDiff = array_diff($arr1 ,$arr2 ) ;
		 		if($arrayDiff){
		 			showMsg(400, join(',',$arrayDiff).' 导入代码不存在，请联系采购或技术');
		 		}
		 	}
		 	
		 	$cgData =[];
		 	foreach ($insertRecords as $kup=>&$vup)
		 	{
		 		////导入校验 是否是高低硫
		 		// 	 			dd(arrayFilterFieldValue($TempData,'fcode',$vup['fcode'])[0]['ffaxAmount'] );
		 		$faxamount =  0 ;
		 		if(empty($vup['fcode']) ){
		 			showMsg(400, ' 导入数据'.$vup['fname'].' 代码为空，请确认' );
		 		}
		 		if(empty($vup['fqty']) ){
		 			showMsg(400, ' 导入数据'.$vup['fname'].' 数量为0，请检查' );
		 		}
		 		
		 		$cgData[$kup]['fbrand'] = $fbrand;
		 		$cgData[$kup]['fbillno'] = $rows['fbillno'];
		 		$cgData[$kup]['fbillnoentry'] = $rows['fbillnoentry'];
		 		$cgData[$kup]['fprodno'] =  $rows['fmodel'] ;
		 		$cgData[$kup]['fcode']= $vup['fcode'] ;
		 		$cgData[$kup]['fnote']= isset($vup['fnote'])?$vup['fnote']:"" ;
		 		$cgData[$kup]['fywQty']= $vup['fqty'] ;
// 		 		$cgData[$kup]['fallAmount']= arrayFilterFieldValue($TempData,'fcode',$vup['fcode'])[0]['ffaxAmount']  ;
		 	}
		 	$db34001  =  columnBiao($FRepKey); ;
		 	$fidArr = array_column($TempData, 'fid');
		 	$jiazhangstr = join(',' , $fidArr);
		 	$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db34001, ['jiazhangdataStr'=>$jiazhangstr],['fid'=>$rows['fid'] ]);
		 	
		 	$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fbillnoentry'=>  "'".$rows['fbillnoentry']."'"  ],true);
		 	$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $cgData);
		 	$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
		 	if($ins  ){
		 		sqlsrv_commit($this->SqlServer);
		 		showMsg(0,'成功'  );
		 	}else {
		 		sqlsrv_rollback($this->SqlServer);
		 		showMsg(1,'失败');
		 	}
	 	
	 }else{
	 	showMsg(1,'数据信息为空');
	 }
	 
	 }
	 
	 
	 /**
	 * 正式报价(加账)管理    导入 金额   gz_YjiazhangcbfMX_HXJZ
	 * 正式加账 后 --  采购 或 技术  
	 * @date: 2023年3月10日 下午1:58:42
	 * @author: juyi
	 */
	 function FJZImportCGJS(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$insertRecords = $data['data'];
	 	
	 	$rows = $data['rows'];
	 	$fmodel = $request->get('fmodel');
	 	//判断 导入 当前 机型 是否一致
	 	$fbillnoentry = $rows['fbillnoentry'] ;
	 	$fbillno = $rows['fbillno'] ;
	 	$fbm ='CG';
	 	if($FRepKey == '34002'){
	 		$fbm ='JS';
	 	}
	 	
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db =columnBiao($FRepKey);
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$fprodno= $insertRecords[0]['fprodno'];
	 		if($fmodel != $fprodno){
	 			showMsg(400,'导入当前选中行机型不一致，请检查');
	 		}
	 		$one = array_unique(array_column($insertRecords, 'fprodno'))  ;
	 		// dd($one);
	 		if(count($one) >1  ){
	 			showMsg(400, ' 机型只支持一个机型导入');
	 		}
	 		
	 		//采购 和 加账
	 		foreach ($insertRecords as $k =>$v)
	 		{
	 			$fcodeStr = substr($v['fcode'],0,2);
	 			if($fcodeStr != 'JZ'){
	 				showMsg(400,'请检查导入代码是否是加账代码');
	 			}
	 		}
	 		
	 		
	 		$arrTT = array_column($insertRecords, 'fcode');
	 		
	 		//机型 JS 是否有 判断
	 		$sql = "select  fbrand ,fmodel,fpower  from gz_YBaseJS where fmodel ='{$fmodel}' " ;
	 		$TempDataJS = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if(empty($TempDataJS)){
	 			showMsg(400, '技术中心不存在这个机型:'.$fprodno.'，请确认');
	 		}
	 		// dd($insertRecords);
	 		
	 		//fcode  是否存在 设置里
	 		$fcode =join("','", $arrTT);
	 		$fcodeStr = "'".$fcode ."'";
	 		$sql = "select fid, fcode from gz_YjiazhangcbfSet where 1=1 and fcode  in ({$fcodeStr})" ;
	 		$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if($SetCodeData){
	 			$arr2 = array_column($SetCodeData, 'fcode');
	 			$arrayDiff = array_diff($arrTT ,$arr2 ) ;
	 			if($arrayDiff){
	 				showMsg(400, join(',',$arrayDiff).' 导入代码不存在，请联系采购或技术');
	 			}
	 		}
	 		
	 		//判断当前机型是否已存在
	 		$tmpfcode = array_column($insertRecords, 'fcode');
	 		$Modelone = array_unique($tmpfcode)  ;
	 		if(count($Modelone) != count($tmpfcode) ){
	 			showMsg(400, 'Excel导入中 fcode有多个，支持唯一fcode导入');
	 		}
	 		$sql = "select fid,fcode,fprodno,fstatus,fallamount,fbillnoentry from gz_YjiazhangcbfMX_HXJZ where fbillnoentry='{$fbillnoentry}' and fcode  in ({$fcodeStr})" ;
	 		// 	echo $sql ;die;
	 		$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		 
	 		$insert1=false;
	 		$update=false;
	 		$insert2 =false;
	 		$cgData =[];
	 		$arr =[];
	 		if($TempData){
	 			// 	 			dd($insertRecords);
	 			/* fbrand" => "WINGD"
	 			 "fcode" => "JZW001"
	 			 "fname" => "HPSCR系统（低硫油）"
	 			 "fprodno" => "6X40-B"
	 			 "fallamount" => "25"
	 			 "_X_ROW_KEY" => "row_9" */
	 			//存在
	 			// 				dd($TempData);
	 			foreach ($insertRecords as $ls =>&$lsVal){
	 				unset($lsVal['_X_ROW_KEY']) ;
	 				unset($lsVal['fname']) ;
	 				$lsVal['fbillnoentry']= $fbillnoentry ;
	 				$lsVal['fbillno']= $fbillno ;
	 				$lsVal['fbm']= $fbm ;
	 				foreach ($TempData as $itemkey=>$itemVal){
	 					if($lsVal['fbillnoentry'] == $itemVal['fbillnoentry'] && $lsVal['fcode'] == $itemVal['fcode'])
	 					{
	 						$arr[$ls]['fid'] =   $itemVal['fid'];
	 						//存在
	 						$arr[$ls]['fprodno'] =  $lsVal['fprodno'] ;
	 						$arr[$ls]['fcode']= $lsVal['fcode'] ;
	 						$arr[$ls]['fallamount']= $lsVal['fallamount'] ;
	 						$arr[$ls]['fbillnoentry']= $fbillnoentry ;
	 						$arr[$ls]['fbillno']= $fbillno ;
	 						$arr[$ls]['fbm']= $fbm ;
	 						unset($insertRecords[$ls]);
	 					}
	 				}
	 			}
	 			// 	 			dd( $arr , $insertRecords);
	 			$insert1=true;
	 			$update=true;
	 			if($insertRecords && count($insertRecords)>0){
	 				$insert1=SqlServerUtil::sqlsrvAllTosql($this->SqlServer,  'gz_YjiazhangcbfMX_HXJZ', $insertRecords);
	 			}
	 			if($arr && count($arr)>0){
	 				//dd($arr);
	 				$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer, 'gz_YjiazhangcbfMX_HXJZ', $arr);
	 			}
	 			
	 		}else{
	 			//无全部导入
	 			foreach ($insertRecords as $kup=>&$vup)
	 			{
	 				if(empty($vup['fcode']) || empty($vup['fprodno']) ){
	 					showMsg(400, ' 导入数据'.$vup['fname'].'机型或代码为空' );
	 				}
	 				$cgData[$kup]['fprodno'] =  $vup['fprodno'] ;
	 				$cgData[$kup]['fcode']= $vup['fcode'] ;
	 				$cgData[$kup]['fallamount']= $vup['fallamount'] ;
	 				$cgData[$kup]['fbillno']= $fbillno ;
	 				$cgData[$kup]['fbillnoentry']= $fbillnoentry ;
	 				$cgData[$kup]['fbm']= $fbm ;
	 				// $cgData[$kup]['fnote']= $vup['fremark'] ;
	 			}
	 			
	 			// 	$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fprodno'=>   "'".$fprodno."'"  ],true);
	 			$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer , 'gz_YjiazhangcbfMX_HXJZ' , $cgData);
	 			$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
	 			// 	 			dd(2233);
	 		}
	 		if(($insert1 && $update) || $insert2  ){
	 			sqlsrv_commit($this->SqlServer);
	 			showMsg(0,'成功');
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}else{
	 		showMsg(1,'数据信息为空');
	 	}
	 	
	 }
	 
	 /**
	 * ICER数据库信息(采购) -- 27011
	 * ICER数据库信息技术   -- 27010
	 * 导入 
	 * @date: 2023年4月9日 下午5:17:58
	 * @author: juyi
	 */
	 function FImportICER(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	
	 	$insertRecords = $data['data'];
	 	$Cshu = $this->getSystemProfile([ 'FSetFFAX',    ]);
	 	$resMX = [];
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db =columnBiao($FRepKey);//数据库
	 	$insertRecords = arraykeyToLowerTo($insertRecords);
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$tmpModel = array_column($insertRecords, 'fegcmodel');
	 		$Modelone = array_unique($tmpModel)  ;
	 		if(count($Modelone) != count($tmpModel) ){
	 			showMsg(400, 'Excel 有多个重复型号Egc,请检查 ');
	 		}
	 		$insert1=false;
	 		$update=false;
	 		$insert2 =false;
	 		$fmodelStr =join("','", $tmpModel );
	 		$fmodelStr = "'".$fmodelStr ."'";
	 	 		
	 		//获取字段
	 		$getVexTableColumnData = $this->getVexTableColumn($FRepKey ) ;
	 		foreach ($insertRecords as $k =>&$v)
	 		{
	 			foreach ($getVexTableColumnData as $kc=>$vc)
	 			{
	 				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='0' ) && $vc['freptype'] == 131 ){
	 					$v[$vc['frepfld']] =0;
	 				}
	 				
	 				if( !empty($v[$vc['frepfld']]) && $v[$vc['frepfld']]>0  && $vc['freptype'] == 131 ){
	 					$v[$vc['frepfld']] =round($v[$vc['frepfld']],$vc['fdecplaces']);
	 				}
	 				
	 				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
	 					$v[$vc['frepfld']] = '';
	 				}
	 				
	 				$resMX[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
	 				
	 				//ICER数据库信息 技术 27010
	 				if($FRepKey == 27010){
	 					$v['fcreatetime']= getCurrentTime();
	 					
	 					$resMX[$k]['fjscg']  = 'JS';
	 					$resMX[$k]['fcreatetime'] = getCurrentTime();
	 				}
	 				
	 				//ICER数据库信息 采购  27011
	 				if($FRepKey == 27011){
	 					$v['fcreatetimecg']= getCurrentTime();
	 					
	 					$resMX[$k]['fjscg']  = 'CG';
	 					$resMX[$k]['fcreatetimecg'] = getCurrentTime();
	 				}
	 				
	 				
	 			}
	 		}
	 		//dd($insertRecords ,$getVexTableColumnData , 111 );
	 		//ICER 管路  导入
	 		if(in_array($FRepKey,['27010','27011'])){
	 			$sql = "select *  from gz_YjzICERDB where fEGCModel in ({$fmodelStr}) " ;
	 			$ICERData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 			$tmp27010 =[];
	 			if($ICERData){
	 				$tmp27010 = arraykeyToLowerTo($ICERData);
	 			}
	 			if($FRepKey == '27010'){
	 				if($tmp27010){
	 					foreach ($tmp27010 as $jsDB)
	 					{
	 						if($jsDB['fstatus'] == 1){
	 							showMsg(400,' 型号：'.$jsDB['fegcmodel'].' ,已审核，无法导入,请检查。');
	 						}
	 					}
	 				}
	 			}
	 			//采购
	 			if($FRepKey == '27011'){
	 				if($tmp27010){
	 					foreach ($tmp27010 as $cgDB)
	 					{
	 						if($cgDB['fstatuscg'] == 1){
	 							showMsg(400,' 型号：'.$cgDB['fegcmodel'].' ,已审核，无法导入,请检查。');
	 						}
	 					}
	 				}
	 			}
	 			$ArrUpload = $tmp27010;
	 			
	 		}
	 		
	 		$cgData =[];
	 		$arr =[];
	 		if($ArrUpload){
// 	 			dd($insertRecords , $ArrUpload);
	 			//  存在
	 			foreach ($insertRecords as $ls =>&$lsVal){
	 				unset($lsVal['_x_row_key']) ;
	 				unset($lsVal['fstatus']) ;
// 	 				dd($lsVal);
	 				//ICER数据库信息(技术) 27010
// 	 				if(in_array($FRepKey,['27010','27011'])){
// 	 					$lsVal['fallamount']= ($lsVal['fguanlu']+$lsVal['ficerkzg']+$lsVal['fpengzhangjie3']
// 	 							+$lsVal['fpengzhangjie']+$lsVal['fbpvbeiya']+$lsVal['fsovjiezhifa']
// 	 							+$lsVal['ffrvliuliang']+$lsVal['fcbvfuiqi']+ $lsVal['fyalicgq16']
// 	 							+$lsVal['fwenducgq16']+$lsVal['fyalibiao12']+$lsVal['fwenduji12']
// 	 							+($lsVal['ficerewfy'] + $lsVal['ficerylfy'] )*(1+$Cshu['fsetffax']/100) );
// 	 				}
	 				foreach ($ArrUpload as $itemkey=>$itemVal){
	 					if($lsVal['fegcmodel'] == $itemVal['fegcmodel']  )
	 					{
	 						//ICER数据库信息(技术) 27010  ，  ICER数据库信息(采购) 27011
	 						//存在
	 						$arr[$ls] = $lsVal;
	 						$arr[$ls]['fid'] = $itemVal['fid'];
	 						$arr[$ls]['fcreatetime'] = getCurrentTime();
	 						if(in_array($FRepKey,['27010' ])){
	 							$arr[$ls]['fguanlu'] = $itemVal['fguanlu']  ;
	 							$arr[$ls]['ficerkzg'] = $itemVal['ficerkzg']  ;
	 							$arr[$ls]['fpengzhangjie3'] = $itemVal['fpengzhangjie3']  ;
	 							$arr[$ls]['fpengzhangjie'] = $itemVal['fpengzhangjie']  ;
	 							$arr[$ls]['fbpvbeiya'] = $itemVal['fbpvbeiya']  ;
	 							$arr[$ls]['fsovjiezhifa'] = $itemVal['fsovjiezhifa']  ;
	 							$arr[$ls]['ffrvliuliang'] = $itemVal['ffrvliuliang']  ;
	 							$arr[$ls]['fcbvfuiqi'] = $itemVal['fcbvfuiqi']  ;
	 							$arr[$ls]['fyalicgq16'] = $itemVal['fyalicgq16']  ;
	 							$arr[$ls]['fwenducgq16'] = $itemVal['fwenducgq16']  ;
	 							$arr[$ls]['fyalibiao12'] = $itemVal['fyalibiao12']  ;
	 							$arr[$ls]['fwenduji12'] = $itemVal['fwenduji12']  ;
	 							
	 							$arr[$ls]['fallamount']= ($itemVal['fguanlu']+$itemVal['ficerkzg']+$itemVal['fpengzhangjie3']
	 									+$itemVal['fpengzhangjie']+$itemVal['fbpvbeiya']+$itemVal['fsovjiezhifa']
	 									+$itemVal['ffrvliuliang']+$itemVal['fcbvfuiqi']+ $itemVal['fyalicgq16']
	 									+$itemVal['fwenducgq16']+$itemVal['fyalibiao12']+$itemVal['fwenduji12']
	 									+($lsVal['ficerewfy'] + $lsVal['ficerylfy'])*(1+$Cshu['fsetffax']/100) );
	 							
	 						}
	 						if(in_array($FRepKey,['27011' ])){
	 							$arr[$ls]['ficergs'] = $itemVal['ficergs']  ;
	 							$arr[$ls]['ficerewfy'] = $itemVal['ficerewfy'] ;
	 							$arr[$ls]['ficerylfy'] = $itemVal['ficerylfy'] ;
	 							$arr[$ls]['ficertjgzfy'] = $itemVal['ficertjgzfy'] ;
	 							$arr[$ls]['fgdzjqq'] = $itemVal['fgdzjqq']  ;
	 							
	 							$arr[$ls]['fallamount']= ($lsVal['fguanlu']+$lsVal['ficerkzg']+$lsVal['fpengzhangjie3']
	 									+$lsVal['fpengzhangjie']+$lsVal['fbpvbeiya']+$lsVal['fsovjiezhifa']
	 									+$lsVal['ffrvliuliang']+$lsVal['fcbvfuiqi']+ $lsVal['fyalicgq16']
	 									+$lsVal['fwenducgq16']+$lsVal['fyalibiao12']+$lsVal['fwenduji12']
	 									+($itemVal['ficerewfy'] + $itemVal['ficerylfy'])*(1+$Cshu['fsetffax']/100) );
	 							
	 						}
	 						unset($insertRecords[$ls]);
	 					}
	 				}
	 			}
// 	 			dd( $arr , $insertRecords);
	 			
	 			$insert1=true;
	 			$update=true;
	 			if($insertRecords && count($insertRecords)>0){
	 				$insert1=SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db, $insertRecords);
	 			}
	 			if($arr && count($arr)>0){
	 				//dd($arr);
	 				$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer, $db, $arr);
	 			}
	 			
	 		}else{
// 	 			dd($insertRecords );
	 			//无全部导入
	 			foreach ($insertRecords as $kup=>&$vup)
	 			{
	 				// _x_row_key
	 				unset($vup['_x_row_key']);
	 				if(in_array($FRepKey,[ '27011'])){
	 					
	 					$insertRecords[$kup]['fallamount']= ($vup['fguanlu']+$vup['ficerkzg']+$vup['fpengzhangjie3']+	$vup['fpengzhangjie']+
	 							$vup['fbpvbeiya']+	$vup['fsovjiezhifa']+$vup['ffrvliuliang']+$vup['fcbvfuiqi']+ $vup['fyalicgq16']+$vup['fwenducgq16']+
	 							$vup['fyalibiao12']+$vup['fwenduji12']  + ($vup['ficerewfy'] + $vup['ficerylfy'] )*(1+$Cshu['fsetffax']/100) );
	 				}
	 				
	 				if(in_array($FRepKey,['27010' ])){
	 					$insertRecords[$kup]['fallamount']=   ($vup['ficerewfy'] + $vup['ficerylfy'] )*(1+$Cshu['fsetffax']/100)  ;
	 				}
	 			}
	 			$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insertRecords);
	 		}
	 		
	 		if(($insert1 && $update) || $insert2  ){
	 			//
	 			if(in_array($FRepKey,[  '27010','27011' ]) ){
	 				SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
	 			}
	 			sqlsrv_commit($this->SqlServer);
	 			showMsg(0,'成功');
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}
	 	
	 }
	
	 
	 /**
	 * 加账管理 Excel导入  -- 技术 。采购 、其他部门
	 * @date: 2023年4月10日 下午7:37:00
	 * @author: juyi
	 * 加账清单(采购)   26005  ==1
		加账清单(技术)  26023  == 2
		加账成本(其他)  26025  ==3
	 */
	 function FImportIJZ(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	
	 	$insertRecords = $data['data'];
	 	
	 	if(empty($insertRecords)){
	 		showMsg(400,'数据导入为空，请检查'); 
	 	}
	  
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db =columnBiao($FRepKey);
	 	$insert1=false;
	 	$update=false;
	 	$insert2 =false;
	 	$cgData =[];
	 	$arr =[];
	 	$resMX =[];
	 	//获取所有机型
	 	$tmp = $insertRecords[0] ;
	 	$tmpCodeT = $tmp['代码'] ;
	 	if( strtoupper(substr( $tmpCodeT,0,2)) != 'JZ'){
	 		showMsg(400,'导入信息有误或代码有误,请检查');
	 	}
	 	$uu = array_keys($tmp);
	 	if(!in_array('代码' ,$uu)){
	 		showMsg(400,'标题代码显示不一致');
	 	}
	 	if(!in_array('名称' ,$uu)){
	 		showMsg(400,'标题名称显示不一致');
	 	}
	 	if(!in_array('单位' ,$uu)){
	 		showMsg(400,'标题单位显示不一致');
	 	}
	 	
	 	unset($tmp['代码']);
	 	unset($tmp['单位']);
	 	unset($tmp['名称']);
	 	unset($tmp['_X_ROW_KEY']);
	 	$fmodelArr = array_keys($tmp) ; 
	 	if(empty($fmodelArr)){
	 		showMsg(400,'机型为空，请检查');
	 	}
	 	//1、判断是否存在技术中心机型 
	 	$fmodelstr =join("','", $fmodelArr);
	 	$fmodelstr = "'".$fmodelstr ."'";
	 	$sqljs = "select fid, fmodel from gz_Ybasejs where 1=1 and fmodel in ({$fmodelstr})" ;
	 	$jsData = SqlServerUtil::execToSql($this->SqlServer,$sqljs );
	 	if(empty($jsData)){
	 		showMsg(400,'技术中心没有该机型，请检查！');
	 	}
	 	if($jsData){
	 		$arr2 = array_column($jsData, 'fmodel');
	 		$arrayDiff = array_diff($fmodelArr ,$arr2 ) ;
	 		if($arrayDiff){
	 			showMsg(400, join(',',$arrayDiff).' 该机型不存在，请联系技术中心');
	 		}
	 	}
	 	// 2、判断加账代码 是否存在  gz_YjiazhangcbfSet
	 	$arrTT = array_column($insertRecords, '代码');
	 	$fcode =join("','", $arrTT);
	 	$fcodeStr = "'".$fcode ."'";
	 	$sql = "select fid, fcode from gz_YjiazhangcbfSet where 1=1 and fcode  in ({$fcodeStr})" ;
	 	$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(empty($SetCodeData)){
	 		showMsg(400,'导入代码不存在，请联系采购或技术或其他部门!');
	 	}
	 	if($SetCodeData){
	 		$arrCode = array_column($SetCodeData, 'fcode');
	 		$codeDiff = array_diff($arrTT ,$arrCode ) ;
	 		if($codeDiff){
	 			showMsg(400, join(',',$codeDiff).' 导入代码不存在，请联系采购或技术或其他部门');
	 		}
	 	}
	 	//3、判断当前代码是否已存在多个 
	 	$ModelMore = array_unique($arrTT)  ;
	 	if(count($ModelMore) != count($arrTT) ){
	 		showMsg(400,  join(',',array_diff($arrTT ,$ModelMore )).'Excel导入中 代码存在相同的');
	 	}
	 	//4、获取数据库加账明细 
	 	$sqljzmx = "select fid,fcode,fprodno,fstatus,fallamount from gz_YjiazhangcbfMX
		where fprodno in ({$fmodelstr}) and fcode  in ({$fcodeStr})" ;
	 	$JZTempData = SqlServerUtil::execToSql($this->SqlServer,$sqljzmx);
	 	
	 	//4.1 判断采购成本是否已经审核
	 	if(in_array(1,array_unique(array_column($JZTempData, 'fstatus')))){
	 		showMsg(400, '当前加账成本机型已审核，无法导入,改为未审核状态');
	 	}
	 	
	 	//5、获取数据转换 
	 	$result =[]; 
	 	foreach ($fmodelArr as $k =>$v){
	 		foreach ($insertRecords as $k1 =>&$v1){
	 			$result[$k][$k1]['fbrand'] =  substr( $v1['代码'],2,1) == 'W'?'WINGD' :'MAN' ; 
	 			$result[$k][$k1]['fprodno'] =  $v  ;
	 			$result[$k][$k1]['fcode'] = $v1['代码'] ;
	 			$result[$k][$k1]['fallamount'] = empty($v1[$v])?0:$v1[$v]  ;
	 		}
	 	}
	 	//6、多维数组转换  
	 	$ArrayRes = getArrayTo($result); 
// 	 	dd($result ,$ArrayRes);
	 	if($JZTempData){
	 		//存在
	 		foreach ($ArrayRes as $ls =>&$lsVal){
	 			$resMX[$ls]['fbrand'] =  $lsVal['fbrand']  ;
	 			$resMX[$ls]['fprodno'] = $lsVal['fprodno'] ;
	 			$resMX[$ls]['fcode']=  $lsVal['fcode'] ;
	 			$resMX[$ls]['fallamount']=  $lsVal['fallamount'] ;
	 			
	 			foreach ($JZTempData as $itemkey=>$itemVal){
	 				if($lsVal['fprodno'] == $itemVal['fprodno'] && $lsVal['fcode'] == $itemVal['fcode'])
	 				{
	 					$arr[$ls]['fid'] =   $itemVal['fid'];
	 					//存在
	 					$arr[$ls]['fprodno'] =  $lsVal['fprodno'] ;
	 					$arr[$ls]['fcode']= $lsVal['fcode'] ;
	 					$arr[$ls]['fallamount']= $lsVal['fallamount'] ;
	 					$arr[$ls]['fbrand'] =  $lsVal['fbrand'] ;
	 					unset($ArrayRes[$ls]);
	 				}
	 			}
	 		}
	 		$insert1=true;
	 		$update=true;
	 		if($ArrayRes){
	 			if(count($ArrayRes)>400){
	 				$each=400;
	 				$total =count($ArrayRes); //数据总数
	 				$step=ceil($total/$each); //insert执行总次数
	 				$j = 1;
	 				$s = $step;
	 				foreach ($ArrayRes as $k=>$v)
	 				{
	 					$arr0=[];
	 					if($j > $step) break;
	 					$arr0 = array_slice($ArrayRes, ($step - $s) * $each, $each);     // 每次取500条
	 					$insert1 =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db ,$arr0);
	 					$j++;
	 					$s--;
	 				}
	 			}else{
	 				$insert1 =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db ,$ArrayRes);
	 			}
	 		}
	 		//更新
	 		if($arr){
	 			if(count($arr)>200){
	 				$each=200;
	 				$total =count($arr); //数据总数
	 				$step=ceil($total/$each); //insert执行总次数
	 				$j = 1;
	 				$s = $step;
	 				foreach ($arr as $k=>$v)
	 				{
	 					$item1=[];$emp1 =[];
	 					if($j > $step) break;
	 					$emp1= array_slice($arr, ($step - $s) * $each, $each);     // 每次取500条
	 					//dd($emp1,$item1);
	 					$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer,$db, $emp1);
	 					$j++;
	 					$s--;
	 				}
	 			}else{
	 				$update=SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,$db,$arr);
	 			}
	 		}
	 		
	 	}else{
	 		//无全部导入
	 		foreach ($ArrayRes as $kup=>&$vup)
	 		{
	 			$cgData[$kup]['fbrand'] =   $vup['fbrand'] ;
	 			$cgData[$kup]['fprodno'] =  $vup['fprodno'] ;
	 			$cgData[$kup]['fcode']= $vup['fcode'] ;
	 			$cgData[$kup]['fallamount']= empty($vup['fallamount'])?0:$vup['fallamount'] ;
	 			
	 			$resMX[$kup]['fbrand'] = $vup['fbrand'] ;
	 			$resMX[$kup]['fprodno'] =  $vup['fprodno'] ;
	 			$resMX[$kup]['fcode']= $vup['fcode'] ;
	 			$resMX[$kup]['fallamount']= empty($vup['fallamount'])?0:$vup['fallamount'] ;
	 		}
// 	 		$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $cgData);
	 		if($cgData){
	 			if(count($cgData)>400){
	 				$each=400;
	 				$total =count($cgData); //数据总数
	 				$step=ceil($total/$each); //insert执行总次数
	 				$j = 1;
	 				$s = $step;
	 				foreach ($cgData as $k=>$v)
	 				{
	 					$arr2=[];$Tmp2 =[];
	 					if($j > $step) break;
	 					$arr2 = array_slice($cgData, ($step - $s) * $each, $each);     // 每次取500条
	 					$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db  , $arr2);
	 					$j++;
	 					$s--;
	 				}
	 			}else{
	 				$insert2 =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db  ,$cgData);
	 			}
			}
			
	 	}
	 	if(($insert1 && $update) || $insert2  ){
	 		sqlsrv_commit($this->SqlServer);
// 	 		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX_JSCG' , $resMX);
	 		
	 		showMsg(0,'成功');
	 	}else {
	 		sqlsrv_rollback($this->SqlServer);
	 		showMsg(1,'失败');
	 	}
	 }
	
	 /**
	 * 采购成本 导入Excel  -- WINGD ，MAN 
	 * @date: 2023年4月11日 上午9:51:08
	 * @author: juyi
	 */
	 function FImportCGCB(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ; 
	 	
	 	$insertRecords = $data['data'];
	 	
	 	$fbrand = 'WINGD';
	 	if($FRepKey == '26009'){
	 		$fbrand = 'WINGD';
	 		$SuBCG = 'W';
	 	}elseif($FRepKey == '26022'){
	 		$fbrand = 'MAN';
	 		$SuBCG = 'M';
	 	}
	 	
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db =columnBiao($FRepKey);
	 	
	 	if(empty($insertRecords)){
	 		showMsg(400,'采购成本数据'.$fbrand.'导入为空，请检查');
	 	}
	 	$insert1=false;
	 	$update=false;
	 	$insert2 =false;
	 	$cgData =[];
	 	$arr =[];
	 	$resMX =[];
	 	//获取所有机型 
	 	$tmp = $insertRecords[0] ;
	 	$tmpCodeT = $tmp['代码'] ;
	 	if( strtoupper(substr( $tmpCodeT,2,1)) != $SuBCG){
	 		showMsg(400,$fbrand.' :导入信息有误不在当前页面或代码有误,请检查');
	 	}
	 	if( strtoupper(substr( $tmpCodeT,0,2)) != 'CG'){
	 		showMsg(400,$fbrand.' :导入信息有误或代码有误,请检查');
	 	}
	 	
	 	$uu = array_keys($tmp);
	 	if(!in_array('代码' ,$uu)){
	 		showMsg(400,'标题代码显示不一致');
	 	}
	 	if(!in_array('名称' ,$uu)){
	 		showMsg(400,'标题名称显示不一致');
	 	}
	 	
	 	unset($tmp['代码']);
	 	unset($tmp['名称']);
	 	unset($tmp['_X_ROW_KEY']);
	 	
	 	$fmodelArr = array_keys($tmp) ;
	 	if(empty($fmodelArr)){
	 		showMsg(400,'机型为空，请检查');
	 	}
	 	//1、判断是否存在技术中心机型
	 	$fmodelstr =join("','", $fmodelArr);
	 	$fmodelstr = "'".$fmodelstr ."'";
	 	$sqljs = "select fid, fmodel from gz_Ybasejs where 1=1 and fmodel in ({$fmodelstr})" ;
	 	$jsData = SqlServerUtil::execToSql($this->SqlServer,$sqljs );
	 	if(empty($jsData)){
	 		showMsg(400,'技术中心没有该机型，请检查！');
	 	}
	 	if($jsData){
	 		$arr2 = array_column($jsData, 'fmodel');
	 		$arrayDiff = array_diff($fmodelArr ,$arr2 ) ;
	 		if($arrayDiff){
	 			showMsg(400, join(',',$arrayDiff).' 该机型不存在，请联系技术中心');
	 		}
	 	}
	 	// 2、判断采购成本 代码 是否存在  gz_Ycaigoucbfset
	 	$arrTT = array_column($insertRecords, '代码');
	 	$fcode =join("','", $arrTT);
	 	$fcodeStr = "'".$fcode ."'";
	 	$sql = "select fid, fcode from gz_Ycaigoucbfset where 1=1 and fcode  in ({$fcodeStr})" ;
	 	$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(empty($SetCodeData)){
	 		showMsg(400,'导入代码不存在，请检查!');
	 	}
	 	if($SetCodeData){
	 		$arrCode = array_column($SetCodeData, 'fcode');
	 		$codeDiff = array_diff($arrTT ,$arrCode ) ;
	 		if($codeDiff){
	 			showMsg(400, join(',',$codeDiff).' 导入代码不存在，请检查');
	 		}
	 	}
	 	//3、判断当前代码是否已存在多个
	 	$ModelMore = array_unique($arrTT)  ;
	 	if(count($ModelMore) != count($arrTT) ){
	 		showMsg(400,  join(',',array_diff($arrTT ,$ModelMore )).'Excel导入中 代码存在相同的');
	 	}
	 	//4、获取数据库加账明细
	 	$sqlcgmx = "select fid,fbrand ,fcode,fprodno,fstatus,fallamount from gz_Ycaigoucbf
	 	where fprodno in ({$fmodelstr}) and fcode  in ({$fcodeStr})" ;
	 	$CGTempData = SqlServerUtil::execToSql($this->SqlServer,$sqlcgmx);
	 	
	 	//4.1 判断采购成本是否已经审核 
	 	if(in_array(1,array_unique(array_column($CGTempData, 'fstatus')))){
	 		showMsg(400, '当前采购成本机型已审核，无法导入,改为未审核状态');
	 	}
	 	//5、获取数据转换
	 	$result =[];
	 	foreach ($fmodelArr as $k =>$v){
	 		foreach ($insertRecords as $k1 =>&$v1){
	 			$result[$k][$k1]['fbrand'] =  substr( $v1['代码'],2,1) == 'W'?'WINGD' :'MAN' ;
	 			$result[$k][$k1]['fprodno'] =  $v  ;
	 			$result[$k][$k1]['fcode'] = $v1['代码'] ;
	 			$result[$k][$k1]['fallamount'] = $v1[$v] ;
	 		}
	 	}
	 	//6、多维数组转换
	 	$ArrayResCG = getArrayTo($result); 
// 	 	dd($ArrayResCG );
	 	if($CGTempData){
	 		//存在
	 		foreach ($ArrayResCG as $ls =>&$lsVal){
	 			$resMX[$ls]['fbrand'] =  $lsVal['fbrand']  ;
	 			$resMX[$ls]['fprodno'] = $lsVal['fprodno'] ;
	 			$resMX[$ls]['fcode']=  $lsVal['fcode'] ;
	 			$resMX[$ls]['fallamount']=  $lsVal['fallamount'] ;
	 			
	 			foreach ($CGTempData as $itemkey=>$itemVal){
	 				if($lsVal['fprodno'] == $itemVal['fprodno'] && $lsVal['fcode'] == $itemVal['fcode'])
	 				{
	 					$arr[$ls]['fid'] =   $itemVal['fid'];
	 					//存在
	 					$arr[$ls]['fprodno'] =  $lsVal['fprodno'] ;
	 					$arr[$ls]['fcode']= $lsVal['fcode'] ;
	 					$arr[$ls]['fallamount']= $lsVal['fallamount'] ;
	 					$arr[$ls]['fbrand'] =  $lsVal['fbrand'] ;
	 					unset($ArrayResCG[$ls]);
	 				}
	 			}
	 		}
	 		
	 		$insert1=true;
	 		$update=true;
	 		if($ArrayResCG){
	 			if(count($ArrayResCG)>400){
	 				$each=400;
	 				$total =count($ArrayResCG); //数据总数
	 				$step=ceil($total/$each); //insert执行总次数
	 				$j = 1;
	 				$s = $step;
	 				foreach ($ArrayResCG as $k=>$v)
	 				{
	 					$arr0=[];
	 					if($j > $step) break;
	 					$arr0 = array_slice($ArrayResCG, ($step - $s) * $each, $each);     // 每次取500条
	 					$insert1 =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db,$arr0);
	 					$j++;
	 					$s--;
	 				}
	 			}else{
	 				$insert1 =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db,$ArrayResCG);
	 			}
	 		}
	 		
	 		//更新 
	 		if($arr){
	 			if(count($arr)>200){
	 				$each=200;
	 				$total =count($arr); //数据总数
	 				$step=ceil($total/$each); //insert执行总次数
	 				$j = 1;
	 				$s = $step;
	 				foreach ($arr as $k=>$v)
	 				{
	 					$item1=[];$emp1 =[];
	 					if($j > $step) break;
	 					$emp1= array_slice($arr, ($step - $s) * $each, $each);     // 每次取500条
	 					//dd($emp1,$item1);
	 					$update=SqlServerUtil::sqlsrvkqUpdateNOFID($this->SqlServer,$db, $emp1);
	 					$j++;
	 					$s--;
	 				}
	 			}else{
	 				$update=SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,$db,$arr);
	 			}	
	 		}
	 		
	 		
	 	}else{
	 		//无全部导入
	 		foreach ($ArrayResCG as $kup=>&$vup)
	 		{
	 			$cgData[$kup]['fbrand'] =   $vup['fbrand'] ;
	 			$cgData[$kup]['fprodno'] =  $vup['fprodno'] ;
	 			$cgData[$kup]['fcode']= $vup['fcode'] ;
	 			$cgData[$kup]['fallamount']= $vup['fallamount'] ;
	 			
	 			$resMX[$kup]['fbrand'] = $vup['fbrand'] ;
	 			$resMX[$kup]['fprodno'] =  $vup['fprodno'] ;
	 			$resMX[$kup]['fcode']= $vup['fcode'] ;
	 			$resMX[$kup]['fallamount']= $vup['fallamount'] ;
	 		}
	 		if($cgData){
	 			if(count($cgData)>400){
	 				$each=400;
	 				$total =count($cgData); //数据总数
	 				$step=ceil($total/$each); //insert执行总次数
	 				$j = 1;
	 				$s = $step;
	 				foreach ($cgData as $k=>$v)
	 				{
	 					$arr2=[];$Tmp2 =[];
	 					if($j > $step) break;
	 					$arr2 = array_slice($cgData, ($step - $s) * $each, $each);     // 每次取500条
	 					$insert2 = SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db, $arr2);
	 					$j++;
	 					$s--;
	 				}
	 			}else{
	 				$insert2 =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,$db,$cgData);
	 			}
	 		}
	 		
	 	}
	 	if(($insert1 && $update) || $insert2  ){
	 		sqlsrv_commit($this->SqlServer);
// 	 		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
	 		showMsg(0,'成功');
	 	}else {
	 		sqlsrv_rollback($this->SqlServer);
	 		showMsg(1,'失败');
	 	}
	 }
	 
	 /**
	 *  加账管理-- 技术 基础设置 删除
	 * @date: 2023年4月11日 下午12:00:52
	 * @author: juyi
	 */
	 function FJzDel(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$resData = $data['data'];
	 	$FItemID = $request ->get('fid');
	 	//
	 	if(empty($resData)){
	 		showMsg(400,'删除数据为空');
	 	}
	 	//拿到所有代码
	 	$fcodeArr = array_column($resData ,'fcode');
	 	$fcode =join("','", $fcodeArr);
	 	$fcodeStr = "'".$fcode ."'";
	 	//已经存在 无法删除代码
	 	$tt = FjzDel($fcodeArr) ;
	 	if($tt){
	 		showMsg(400,$tt.', 无法删除，已存在');
	 	}
	 	//判断 代码是否已经存在
	 	$sql = "select fprodno from gz_YjiazhangcbfMX where 1=1 and fcode  in ({$fcodeStr}) group by fprodno " ;
	 	$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(!empty($SetCodeData)){
	 		showMsg(400,'代码已存在加账成本中，无法删除!');
	 	}
	 	
	 	//正式报价
	 	$sql = "select fprodno from gz_Yjiazhangcbf_BAOJIA where 1=1 and fcode  in ({$fcodeStr}) group by fprodno" ;
	 	$ZSCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(!empty($ZSCodeData)){
	 		showMsg(400,'正式报价列表中代码已存在，使用中，无法删除!');
	 	}
	 	
	 	//判断
	 	$qkid = sqlsrv_query($this->SqlServer,"DELETE gz_YjiazhangcbfSet WHERE fid in ({$FItemID}) ");
	 	if($qkid){
	 		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
	 		showMsg(200,'删除成功');
	 	}else{
	 		showMsg(400,'删除失败');
	 	}
	 }
	 
	 
	 /**
	  *  采购成本管理--  基础设置 删除
	  * @date: 2023年4月11日 下午12:00:52
	  * @author: juyi
	  */
	 function FCGDel(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$resData = $data['data'];
	 	$FItemID = $request ->get('fid');
	 	//
	 	if(empty($resData)){
	 		showMsg(400,'删除数据为空');
	 	}
	 	//拿到所有代码
	 	$fcodeArr = array_column($resData ,'fcode');
	 	$fcode =join("','", $fcodeArr);
	 	$fcodeStr = "'".$fcode ."'";
	 	//判断 代码是否已经存在
	 	$sql = "select fprodno from gz_Ycaigoucbf where 1=1 and fcode  in ({$fcodeStr}) group by fprodno" ;
	 	$SetCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(!empty($SetCodeData)){
	 		showMsg(400,'代码已存在使用中，无法删除!');
	 	}
	 	//经营报价
	 	$sql = "select fprodno from gz_Ycaigoucbf_ZLCCG where 1=1 and fcode  in ({$fcodeStr}) group by fprodno" ;
	 	$JYCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(!empty($JYCodeData)){
	 		showMsg(400,'经营报价列表中代码已存在，使用中，无法删除!');
	 	}
	 	//正式报价
	 	$sql = "select fprodno from gz_Ycaigoucbf_BAOJIA where 1=1 and fcode  in ({$fcodeStr}) group by fprodno" ;
	 	$ZSCodeData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 	if(!empty($ZSCodeData)){
	 		showMsg(400,'正式报价列表中代码已存在，使用中，无法删除!');
	 	}
	 	//判断
	 	$qkid = sqlsrv_query($this->SqlServer,"DELETE gz_YcaigoucbfSet WHERE fid in ({$FItemID}) ");
	 	if($qkid){
	 		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
	 		showMsg(200,'删除成功');
	 	}else{
	 		showMsg(400,'删除失败');
	 	}
	 }
	 
	  /**
	  * 业务需求 --确认加账 
	  * @date: 2023年4月29日 上午9:42:47
	  * @author: juyi
	  */
	 function yewuQrJZ(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$fbillno = $request->get('fbillno') ;
	 	$rows = $request->get('rows') ;
	 	$insertRecords = $data['data'];
	 	 
	 	if(empty($rows['fmodel'])  || empty($fbillno)){
	 		showMsg(400,'机型 参数错误');
	 	}
	 	if(empty($rows)){
	 		showMsg(400,'当前行未选中');
	 	}
	 	if( $rows['fisjiazhang'] == '否'){
	 		showMsg(400,'当前行选择加账为否，无法新增加账信息，请检查');
	 	}
	 	if(empty($insertRecords)){
	 		showMsg(400,'没有选择加账');
	 	}
	 	//
	 	$fmodel = $rows['fmodel'] ;
	 	$sxqty = $rows['fqty'] ;
	 	$sql = "select fbrand  from gz_Ybasejs where  fmodel='{$fmodel}'  " ;
	 	$jsData = SqlServerUtil::execToSql($this->SqlServer,$sql,2);
	 	if(empty($jsData)){
	 		showMsg(400, $fmodel.' 机型不存在，请检验，');
	 	}
	 	$fbrand =  strtoupper(str_replace(' ','', $jsData['fbrand'])) ;
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$db = 'gz_Yjiazhangcbf';
	 	$db14009 = 'gz_YBaseSC' ;
	 	if(!empty($insertRecords)){
	 		//判断当前机型是否已存在
	 		$arr1 = array_column($insertRecords, 'fcode'); 
	 		
	 		$fcode =join("','", $arr1);
	 		$fcodeStr = "'".$fcode ."'";
 
	 		if($rows['fisscr'] !='否'){
	 			if(strtolower($rows['fisscr']) == 'iscr' ){
	 				if( !isValueInArrayiSCR($insertRecords,'iSCR')  ){
	 					showMsg(400,'加账清单没有选择带iSCR  ，或加账清单基础设置没添加，请检查 ');
	 				}
	 			}else{
	 				//清单 必有
	 				if( !isValueInArrayICER($insertRecords, 'PSCR' )  ){
	 					showMsg(400, '  业务需求 选择`是否含SCR`,与加账清单 SCR高低硫 不一致 , 请检查 ');
	 				}
	 				
	 				if( $rows['fisscr'] ==  "LPSCR"){
	 					if( !isValueInArrayICER($insertRecords, 'LPSCR' )  ){
	 						showMsg(400, '业务需求 选择`是否含SCR`,与加账清单 LPSCR高低硫 不一致 , 请检查 ');
	 					}
	 				}
	 				if( $rows['fisscr'] ==  "HPSCR"){
	 					if( !isValueInArrayICER($insertRecords, 'HPSCR' )  ){
	 						showMsg(400, ' 业务需求 选择`是否含SCR`,与加账清单 HPSCR高低硫 不一致 , 请检查 ');
	 					}
	 				}	
	 				
// 	 				$fcodeTmp = isHPLPSCRONE($fbrand , $arr1) ;
// 	 				if( $fcodeTmp=== true){
// 	 					showMsg(400,  'SCR高低硫选择不正确，请检查0 ');
// 	 				}
// 	 				if(isHPLPSCR($fbrand , strtoupper($fcodeTmp) ,$rows['fisscr'],$rows['fscrlowup'] )){
// 	 					showMsg(400,  'SCR高低硫是否正确，请检查1 ');
// 	 				}
	 			}
	 		}
	 		
	 		// 判断 高硫  3.5%   如果硫含量3.5%，把LDCL系统的成本自动放在主机成本总价里。
	 		if($FRepKey != '34001'){
    	 		if($fbrand == 'MAN'){
    		 		if( stripos( $rows['fzhujiranliaos'] , '3.5' ) !== false){
    		 			if(!in_array('JZM028', $arr1)){
    		 				showMsg(400, '硫含量'.$rows['fzhujiranliaos']. ',LDCL系统未添加，请检查');
    		 			}
    		 		}
    	 		}
	 		}
	 		
	 		//ICER 
	 		if($FRepKey == '14009'){
	 			// 甲醇机项目在市场部需求环节，是否含EGR，选择不能为否。且加账清单需要有EGR或者ECOEGR
// 	 			if( stripos( strtoupper($rows['fmodel']) , 'LGIM' ) !== false)    {
// 	 				if( !isValueInArrayICER($insertRecords,'EGR')  ){
// 	 					showMsg(400,'加账清单没有选择带EGR  ，或加账清单基础设置没添加，请检查 ');
// 	 				}
// 	 			}
	 			//有ICER
	 			if( $rows['fegcmodel'] !='无' ){
	 				$fegcmodelICER = 'EGC'.$rows['fegcmodel'];
	 				if( !isValueInArrayICER($insertRecords,$fegcmodelICER)  ){
	 					showMsg(400,'加账清单没有选择ICER ('.$fegcmodelICER .')，或加账清单基础设置没添加，请检查 ');
	 				}
	 			}
	 			
	 			if( $rows['fegcmodel'] =='无' || empty($rows['fegcmodel']) ){
	 				$fegcmodelICER_0 = 'EGC' ;
	 				if( isValueInArrayICER($insertRecords,$fegcmodelICER_0)  ){
	 					showMsg(400,'加账清单含有ICER 与  业务需求市场部信息选择EGC型号不一致  ，请检查 ');
	 				}
	 			}
	 		}
	 		
	 		//判断导入代码是否在 加账设置里
	 		$sql = "select fcode,fqty,ffaxAmount from gz_YjiazhangcbfSet where  fcode  in ({$fcodeStr}) and fbrand ='{$fbrand}'" ;
	 		$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql);
	 		if(empty($TempData)){
	 			showMsg(400,'当前品牌'.$fbrand.'导入品牌对应代码是否正确');
	 		}
	 		if($TempData){
	 			$arr2 = array_column($TempData, 'fcode');
	 			$arrayDiff = array_diff($arr1 ,$arr2 ) ;
	 			if($arrayDiff){
	 				showMsg(400, join(',',$arrayDiff).' 导入代码不存在，请联系采购或技术');
	 			}
	 		}
	 		
	 		$cgData =[];
	 		$jiazhangstr ='' ;
	 		foreach ($insertRecords as $kup=>&$vup)
	 		{
	 			$jiazhangstr .= ','.$vup['fid'];
	 			////导入校验 是否是高低硫
	 			$faxamount =  0 ;
	 			if(empty($vup['fcode']) ){
	 				showMsg(400, ' 导入数据'.$vup['fname'].' 代码为空，请确认' );
	 			}
	 			if(empty($vup['fqty']) ){
	 				showMsg(400, ' 导入数据'.$vup['fname'].' 数量为0，请检查' );
	 			}
	 			
	 			$cgData[$kup]['fbrand'] = $fbrand ;
	 			$cgData[$kup]['fbillno'] = $rows['fbillno'];
	 			$cgData[$kup]['fprodno'] =  $rows['fmodel'] ;
	 			$cgData[$kup]['fcode']= $vup['fcode'] ;
	 			$cgData[$kup]['fywQty']= 1 ;
	 			$cgData[$kup]['fnote']=  "" ;
	 			$cgData[$kup]['fallAmount']= arrayFilterFieldValue($TempData,'fcode',$vup['fcode'])[0]['ffaxAmount']  ;
	 			
	 		}
	 		$jiazhangstr = trim($jiazhangstr , ',') ;
	 		 
	 		$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db14009, ['jiazhangdataStr'=>$jiazhangstr],['fid'=>$rows['fid'] ]);
	 		$del = SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fbillno'=>  "'".$fbillno."'"  ],true);
	 		$ins = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $cgData);
	 		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $cgData ,$opername);
	 		if($ins && $u2  ){
	 			sqlsrv_commit($this->SqlServer);
	 			showMsg(0,'成功'  );
	 		}else {
	 			sqlsrv_rollback($this->SqlServer);
	 			showMsg(1,'失败');
	 		}
	 		
	 		
	 	}else{
	 		showMsg(1,'数据信息为空');
	 	}
	 	
	 }
	 
	 
	 /**
	 * 业务 需求  == z针对修改，数量 和备注 
	 * @date: 2023年4月29日 上午11:03:25
	 * @author: juyi
	 */
	 public function yewuSaveJZ(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$fbillno = $request->get('fbillno') ;
	 	$row = $request->get('row') ;
	 	$insertRecords = $data['data'];
	 	if($FRepKey == '14009'){
	 		$db = 'gz_Yjiazhangcbf';
	 	}elseif( $FRepKey == '34001'){
	 		$db = 'gz_Yjiazhangcbf_HXJZ';
	 	}
	 	if(empty($insertRecords)){
	 		showMsg(400,'没有选择加账修改');
	 	}
	 	$fcode = $insertRecords['代码'] ;
	 	$sql = "select fcode,fqty,ffaxAmount from gz_YjiazhangcbfSet where  fcode  = '{$fcode}' " ;
	 	$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql ,2);
	 	if(empty($TempData)){
	 		showMsg(400,'加账代码不存在');
	 	}
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	if( $FRepKey == '14009'){
	 		$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db, ['fywQty'=>$insertRecords['数量'],'fnote'=>$insertRecords['备注']],['fbillno'=>$fbillno , 'fcode'=>$fcode ]);
	 	
	 	}elseif( $FRepKey == '34001'){
	 		$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db, ['fywQty'=>$insertRecords['数量'],'fnote'=>$insertRecords['备注']],['fbillnoentry'=>$row['fbillnoentry'] , 'fcode'=>$fcode ]);
	 	}
	 	if( $u2  ){
	 		sqlsrv_commit($this->SqlServer);
	 		showMsg(0,'成功'  );
	 	}else {
	 		sqlsrv_rollback($this->SqlServer);
	 		showMsg(1,'失败');
	 	}
	 	
	 }
	 
	 /**
	 * 文件用途描述
	 * yewuDelJZ
	 * @date: 2023年4月29日 上午11:27:07
	 * @author: juyi
	 */
	 function yewuDelJZ(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$data =  $request->all() ;
	 	$resData = $data['data'];
	 	$FItemID = $request ->get('fid');
	 	//
	 	if(empty($resData)){
	 		showMsg(400,'删除数据为空');
	 	}
	 	$fbillno = $request->get('fbillno');
	 	$row = $request->get('row');
	 	$jiazhangdatastr = $row['jiazhangdatastr'] ;
	 	$jiazhangdatastrTmp = ','.$row['jiazhangdatastr'] ;
// 	 	 dd( $request ->all() );
	 	//拿到所有代码
	 	$fcodeArr = array_column($resData ,'代码');
	 	$fcode =join("','", $fcodeArr);
	 	$fcodeStr = "'".$fcode ."'";
	  
	 	$sql = "select fid,fcode  from gz_YjiazhangcbfSet where  fcode  in ({$fcodeStr}) " ;
	 	$TempData = SqlServerUtil::execToSql($this->SqlServer,$sql  );
	    
	 	if(empty($TempData)){
	 		showMsg(400,'加账代码不存在');
	 	}
	 	foreach ($TempData as $k =>$v)
	 	{
	 		$jiazhangdatastrTmp = str_replace(','.$v['fid'] ,'', $jiazhangdatastrTmp ) ;
	 	}
	 	$jiazhangdatastrTmp = trim($jiazhangdatastrTmp,',');
	 	// dd($sql , $TempData , $jiazhangdatastrTmp );
	 	  
	 	// 启动事务
	 	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	 		die(print_r(sqlsrv_errors(), true));
	 	}
	 	$qkid = true;
	 	$u2 = true;
	 	if($FRepKey == '14009'){
	 		$db14009 = columnBiao($FRepKey) ;
	 		//判断
	 		$sql = "DELETE gz_Yjiazhangcbf WHERE fcode in ({$fcodeStr}) and  fbillno = '{$fbillno}' " ;
	 		$qkid = sqlsrv_query($this->SqlServer, $sql );
	 		
	 		$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db14009, ['jiazhangdataStr'=>$jiazhangdatastrTmp],['fid'=>$row['fid'] ]);
	 	}elseif( $FRepKey == '34001'){
	 		$db34001 = columnBiao($FRepKey) ;
	 		$fbillnoentry = $row['fbillnoentry'] ;
	 		//判断
	 		$sql = "DELETE gz_Yjiazhangcbf_HXJZ  WHERE fcode in ({$fcodeStr}) and  fbillnoentry = '{$fbillnoentry}' " ;
	 		$qkid = sqlsrv_query($this->SqlServer, $sql );
// 	 		echo $sql;die;
	 		$u2 = SqlServerUtil::exeupdateTosql($this->SqlServer, $db34001, ['jiazhangdataStr'=>$jiazhangdatastrTmp],['fid'=>$row['fid'] ]);
	 	}
	 	
	 	if($qkid && $u2){
	 		sqlsrv_commit($this->SqlServer);
	 		showMsg(0,'成功');
	 	}else{
	 		sqlsrv_rollback($this->SqlServer);
	 		showMsg(1,'失败');
	 	}
	 }
	 
	 /**
	 * 正式报价 == 审核 权限   
	 * @date: 2023年4月29日 下午6:30:30
	 * @author: juyi
	 */
	 function FstatusCheck(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	
	 	$CsData =  $this->getSystemProfile(['FSetStatusCheck']);
	 	$quanxian = 0 ;
	 	if($opername != 'manager'){
	 		if(!empty($CsData['fsetstatuscheck'])){
	 			//数组 
	 			$Arr = explode(',' , $CsData['fsetstatuscheck']);
	 			$fbillnoStrTmp = join("','",$Arr )  ;
	 			$groupStr = "'".$fbillnoStrTmp ."'";
	 			
	 			$sql = "SELECT  ad.username,g.fname ,fld.FFunc
	 			from gz_user_group ug
	 			left join  gz_admin ad   on ug.userid = ad.id
	 			left join gz_group g  on  g.id = ug.groupid
	 			left join gz_ObjectAccessField fld on fld.fgroupid = g.id
	 			where  ad.username ='{$opername}' and g.fname in ({$groupStr}) ";
	 			
	 			$groupData = SqlServerUtil::execToSql($this->SqlServer, $sql );
	 			if(!empty($groupData)){
	 				$quanxian = 1 ;
	 			}
	 		}
	 	}
	 	showMsg(0,'成功' ,$quanxian);
	 }
	 
	 /**
	 * 文件用途描述
	 * @date: 2023年5月8日 下午12:01:51
	 * @author: juyi
	 */
	 function task(Request $request){
	 	date_default_timezone_set('PRC');
	 	Log::info('执行Sql时间 -- '.getCurrentTime(). "\r\n \r\n" );
	 	$sql =" DECLARE @DBCCString NVARCHAR(1000)
			DECLARE @TableName VARCHAR(100)
			DECLARE Cur_Index CURSOR FOR
			  SELECT Name AS TblName FROM sysobjects WHERE xType='U' and name not like 'tm%' 
			  ORDER BY TblName
			FOR READ ONLY
			OPEN Cur_Index
			FETCH NEXT FROM Cur_Index INTO @TableName
			WHILE @@FETCH_STATUS=0
			BEGIN
			  SET @DBCCString = 'DBCC DBREINDEX(@TblName,'''')WITH NO_INFOMSGS'
			  EXEC SP_EXECUTESQL  @DBCCString,N'@TblName VARCHAR(100)',@TableName
			  --PRINT convert(varchar(40),getdate(),121)+'重建表' + @TableName +'的索引........OK!'
			  FETCH NEXT FROM Cur_Index INTO @TableName
			END
			CLOSE Cur_Index
			DEALLOCATE Cur_Index
			--print convert(varchar(40),getdate(),121)+'操作完成！'
			
			--更新统计信息
			declare @SqlStr1 nvarchar(max)
			set @SqlStr1=''
			select  @SqlStr1= @SqlStr1+ + 'UPDATE STATISTICS '+name+ ';'  from sysobjects where xtype='U'  and (name not like 'TMP%') 
			exec (@SqlStr1) ";
	 	$u2 = SqlServerUtil::sqlexecNo($this->SqlServer, $sql );
	 	Log::info('执行Sql--- '.$u2. "\r\n \r\n" );
	 	showMsg(200,'成功');
	 }
	 
	 /**
	 * 加账成本管理-基础设置，对部门设置。多个以英文逗号(,)分割。（示例：采购部,技术中心）
	 * 
	 * @date: 2023年5月11日 上午11:42:53
	 * @author: juyi
	 */
	 function FSetbumen(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername= $request->get('opername');
	 	$Fbumen = $request->get('fbumen')??0;
	 	$result =[];
	 	$CsData =  $this->getSystemProfile(['FSetBuMen']);
	 	
	 	if(empty($CsData['fsetbumen'])){
	 		showMsg(400,'请在参数设置好部门信息' );
	 	}
	 	$Arr = explode(',' , $CsData['fsetbumen']);
	 	//过滤数组为空
	 	$result = array_filter($Arr);
	  	
	 	showMsg(0,'成功' ,$result);
	 }
	 
	 
	 /**
	 * SCRSet 设置 列表 
	 * @date: 2023年8月29日 下午3:44:16
	 * @author: juyi
	 */
	 function FSCRSetList(Request $request){
	 	$FRepKey = $request->get('FRepKey');
	 	$opername = $request->get('opername'); //当前登录人名称      '测试3'
	 	$keyword = $request->keyword;
	 	$keywordStr = '';
	 	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
	 		$keywordStr = " and  charindex('{$keyword}',fpowerkW) >0 " ;
	 	}
// 	 	$baseSql = " select fpowerkW as '功率 (kW)'  , HPSCRL as 'HPSCR价格(低硫、万元)', HPSCRH as 'HPSCR价格(高硫、万元)', 
// 		LPSCRL as 'LPSCR价格(低硫、万元)',  LPSCRH as 'LPSCR价格(高硫、万元)' from gz_YSCRSet " ;
	 	$baseSql = " select * from gz_YSCRSet  where 1=1 {$keywordStr}  order by fsort " ;
	 	
	 	$res = SqlServerUtil::execTosqlOK($this->SqlServer,  $baseSql); 
	 	$result =[];
	 	if($res){
	 		$result = arraykeyToLower($res);
	 		foreach ($result as $k1=>&$v1)
	 		{
	 			foreach ($v1 as $k2=>$v2)
	 			{
	 				if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.0000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
	 					$v1[$k2] = floatval($v2);
	 				}
	 				// fnbfhyx
	 			}
	 		}
	 	}
	 	showMsg(0,'成功' , $result) ;
	 }
	 
	 /**
	  * try {
			    // 可能发生异常的代码
			} catch (CustomException $e) {
			    // 自定义异常处理逻辑
			} catch (Exception $e) {
			    // 默认的异常处理逻辑
			}

	 * SCRSet -- 保存
	 * @date: 2023年8月29日 下午4:18:53
	 * @author: juyi
	 */
	 function FSCRSetSave(Request $request){
	 	$FRepKey = $request->FRepKey?$request->FRepKey:26028;
	 	$opername = $request->get('opername');
	 	$result =[];
	 	$message = 'SCR 提交，保存接口一会在 调试 ';
	 	$data = [];
	 	$db = columnBiao($FRepKey);//表名  -- 
	 	$updateRecords = $request->updateRecords ; //修改 
	 	$insertRecords = $request->insertRecords ; //新增 
	 	
	 	$allData =  array_merge($insertRecords, $updateRecords) ;
	 	if(empty($allData) ){
	 	    showMsg(400,'没有数据新增修改 ');
	 	}
	 	$getVexTableColumnData = $this->getVexTableColumn($FRepKey  ) ;
	 	if($updateRecords && count($updateRecords)>0){
    	 	if(empty($updateRecords)){
    	 		showMsg(400,'没有修改内容，请检查');
    	 	}
    // 	 	dd($getVexTableColumnData , $updateRecords);
    	 	$fidField ='fid' ;
    	 	$resMX =[];
    	 	try {
    		 	foreach ($updateRecords as $k=>&$v)
    		 	{
    		 		$where[$fidField] = $v[$fidField];
    		 		foreach ($getVexTableColumnData as $kc=>$vc)
    		 		{
    		 			if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    		 				$v[$vc['frepfld']] = 0;
    		 			}
    		 			
    		 			if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    		 				$v[$vc['frepfld']] = '';
    		 			}
    		 			$insData[$vc['frepfld']] = $v[$vc['frepfld']] ;
    		 			$insData[ 'fcreatetime' ] = getCurrentTime() ;
    		 			
    		 			$resMX[$k]['fcreatemanager'] = $opername;
    		 			$resMX[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    		 			$resMX[$k][ 'fcreatetime' ] = getCurrentTime() ;
    		 		}
    		 		
//     		 		unset($insData['fsort']);
    		 		unset($insData['fstatus']);
    		 		unset($insData['checkname']);
    	// 	 		dd($db,$insData,$where);
    		 		SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
    		 		
    		 		//写日志
    		 		$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $insData ,$opername );
    		 	}
    		 	//明细
    		 	SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
    		 	
    		 	showMsg(0, '成功' ) ;
    		 	
    	 	} catch (Exception $e) {
    	 		// 默认的异常处理逻辑
    	 		dd($e);
    	 		showMsg(400, $e  ) ;
    	 	}
	 	}else if($insertRecords && count($insertRecords)>0 ) {
	 	    $fidField ='fid' ;
	 	    $resMX =[];
	 	    try {
	 	        foreach ($insertRecords as $k=>&$v)
	 	        {
	 	            foreach ($getVexTableColumnData as $kc=>$vc)
	 	            {
	 	                if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
	 	                    $v[$vc['frepfld']] = 0;
	 	                }
	 	                
	 	                if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
	 	                    $v[$vc['frepfld']] = '';
	 	                }
	 	                $insData[$vc['frepfld']] = $v[$vc['frepfld']] ;
	 	                $insData[ 'fcreatetime' ] = getCurrentTime() ;
	 	                
	 	                $resMX[$k]['fcreatemanager'] = $opername;
	 	                $resMX[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
	 	                $resMX[$k][ 'fcreatetime' ] = getCurrentTime() ;
	 	            }
	 	            
// 	 	            unset($insData['fsort']);
	 	            unset($insData['fstatus']);
	 	            unset($insData['checkname']);
	 	            // 	 		dd($db,$insData,$where);
	 	            SqlServerUtil::sqlsrvCreate($this->SqlServer,$db,$insData  );
	 	            
	 	            //写日志
	 	            $this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $insData ,$opername );
	 	        }
	 	        //明细
	 	        SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
	 	        
	 	        showMsg(0, '成功' ) ;
	 	    } catch (\Exception $e) {
	 	        // 默认的异常处理逻辑
	 	        showMsg(400, $e  ) ;
	 	    }
	 	    
	 	}
	 	
	 
	 }
	 
	/**
	* 参数 配置
	* @date: 2023年9月19日 上午10:43:56
	* @author: juyi
	*/
	 function FcenshuCSJSet(Request $request){
	 	$opername = $request->get('opername');
	 	$fcsjval = $request->  fcsjval ??0;
	 	$fbackval = $request->  fbackval ??0;
	 	
	 	// 0 - 默认 ，自动添加 无  ，， 1-- 自动添加 全部 ， 2 - 不添加 ,3-- 去除CCS,ABS,LR,BV,DNV , 4-- 去除CCS,ABS,LR,BV,DNV ,NK
	 	// 5 -- 去除CCS,ABS,LR,BV,DNV ,NK 后 ，自动添加 全部 ，
	 	$csSetData = $this->getSystemProfile(['FSetChuanjisheBase',]);
// 	 	CCS,ABS,LR,BV,NK,DNV,RINA,KR
	 	$result=[];
	 	if($csSetData['fsetchuanjishebase']){
	 		$result = explode(',',$csSetData['fsetchuanjishebase']);
	 		if($fcsjval == 0){
	 			array_push($result,'无');
	 		}elseif($fcsjval == 1){
	 			array_push($result,'全部') ;
	 		} elseif($fcsjval == 3){
	 			$result = array_diff( $result , ['CCS','ABS','LR','BV','DNV' ]) ;
	 		} elseif($fcsjval == 4){
	 			$result = array_diff( $result , ['CCS','ABS','LR','BV','DNV','NK' ]) ;
	 		} elseif($fcsjval == 5){
	 			$result = array_diff( $result , ['CCS','ABS','LR','BV','DNV','NK' ]) ;
	 			array_push($result,'全部') ;
	 		} 
	 	}
	 	if($fbackval == 1){
	 		return $result ;
	 	}else{
	 		showMsg(0, '成功', array_values($result ) ) ;
	 	}
	 }
	 
	 
	 
	 
	 

}
